다음 코드가 있으며 유효성 검사 규칙이 작동하지 않습니다. 도움을 요청하십시오! 활성 x 컨트롤이 나타나지 않는 것처럼 웹 브라우저는 javascript 코드를 인식하지 못합니다.자바 스크립트 유효성 검사 규칙이 작동하지 않습니다.
<HTML>
<head>
<title>Exam entry</title>
<script lanuage="javascript" type="text/javascript">
var result = true;
function validateForm() {
var msg="";
if (document.ExamEntry.name.value=="") {
msg+="you must enter your name \n";
document.ExamEntry.name.focus();
document.getElementById('name').style.color="red";
result = false;
}
if (document.ExamEntry.subject.value=="") {
msg+("You must enter the subject \n");
document.ExamEntry.subject.focus();
document.getElementById('subject').style.color="red";
result false;
}
if (document.ExamEntry.ExaminationNumber.value=="") {
msg+("You must enter the Examination Number \n");
document.ExamEntry.ExaminationNumber.focus();
document.getElementById('ExaminationNumber').style.color="red";
result false;
}
if(msg==""){
return result;
}
{
alert(msg)
return result;
}
}
</script>
<form>
<input type="radio" name="qualification" value="GCSE">GCSE<br>
<input type="radio" name="qualification" value="AS">AS<br>
<input type="radio" name="qualification" value="A2">A2<br>
</form>
</head>
<body>
<h1>Exam Entry Form</h1>
<form name="ExamEntry" method="post" action="success.html">
<table width="50%" border="0">
<tr>
<td id="name">Name</td>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<td id="subject">Subject</td>
<td><input type="text" name="subject" /></td>
</tr>
<tr>
<td id="ExaminationNumber">ExaminationNumber</td>
<td><input type="text" name="ExaminationNumber" /></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Submit" onclick="return validateForm();" /></td>
<td><input type="reset" name="Reset" value="Reset" /></td>
</tr>
</table>
</form>
</body>
</HTML>
누군가가 도와 주실 수 있습니까?
: 나는
getInputByName
라는 도우미 함수를 추가? –그들은 아직 작동하지 않지만 더 이상 도움이되지 않습니까? 색상을 변경하지만 오류 메시지를 표시하지 않기 때문에 javascript가 실행 중입니까? –
@SamanthaMclemon : 당신이'msg + = (...)'을 의미 할 때 당신은 몇 곳에서'msg + (...)'를 쓰고 있습니다. –