초보자 용 자바 스크립트 사용자이고이 HTML 양식을이 자바 스크립트 함수로 전달하고 이름 변수를 출력하려고합니다. 버튼을 클릭하면 양식 입력이 지워지고 자바 스크립트로 전달되지 않는 양식에 그대로 남아있게됩니다.javascript를 통해 html 양식 변수를 제출할 때 아무런 변화가 없습니다.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Life Insurance Calculator</title>
<script type="text/javascript">
var title = "Welcome to Life Insurance Co..!";
//Declaring variable title
document.writeln(title.fontsize(8).fontcolor('red'));
//Printing out the title on the page
function Name(form){
var customername = document.getElementByID("name").value;
document.write(customername);
}
</script>
</head>
<body>
<form name = "LifeCalcForm" action="" method="get">
<p>To get a life insurance quote, please tell us about yourself.</p>
<p><i>Note:only those under the age of 80 and non-smokers may apply</i></p>
<p>Enter your name: <input type="text" name="name" /></p>
<input type="submit" value="Calculate" onClick="Name(this.form)">
</form>
</body>
</html>
"자바 스크립트 제출"- 당신은 무엇을 의미합니까? – Alex
자바 스크립트 함수가 호출되지 않고 이름을 출력하지 않습니다. – user2869602
onload가 실행 된 후에는'document.write'를 사용할 수 없습니다. 당신의 경우에 온로드 (onclick)가 온로드 후에 거의 확실하게 발생하기 때문에 이런 일이 발생합니다. 그 중에서도 기본 제출 동작을 방지하기 위해'onclick'에서'false를 반환해야합니다. – Steve