0
我目前在學習Javascript,並且遇到以下腳本存在的問題。好像我還沒有宣佈這些功能。任何幫助將不勝感激。謝謝。錯誤檢查功能在Javascript中不起作用
<!DOCTYPE html PUBLIC 「-//W3C//DTD XHTML 1.0 Transitional//EN」
「http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd」>
<html xmlns=」http://www.w3.org/1999/xhtml」>
<head>
<title>Chapter 7: Example 4</title>
<script type="text/javascript">
function btnCheckForm_onclick() {
var myForm = document.form1;
if (myForm.txtAge.value == "" || myForm.txtName.value == "") {
alert("please complete the form");
if (myForm.txtName.value == "") {
myForm.txtName.focus();
} else {
myForm.txtAge.focus():
} else {
alert("Thanks for completing the form");
}
}
function txtAge_onblur() {
var txtAge = document.form1.txtAge;
if (isNaN(txtAge.value) == true) {
alert("please enter a valid age");
txtAge.focus();
txtAge.select();
}
}
function txtName_onchange() {
window.status = "Hi " + document.form1.txtName.value;
}
</script>
<body>
<form action="" name="form1">
Please enter the following details:
<p>
Name:
<br />
<input type="text" name="txtName" onchange="txtName_onchange()" />
</p>
<p>
Age:
<br />
<input type="text" name="txtAge" onblur="txtAge_onblur()" size="3" maxlength="3" />
</p>
<p>
<input type="button" value="Check Details" name="btCheckForm" onclick="btnCheckForm_onclick()">
</form>
</body>
</html>
===可能在JS會更好。例如1 =='1'將返回true,但1 ==='1'將返回false – biobirdman
您可以正確格式化您的代碼嗎?使用提供的文本,您會收到錯誤是正常的。例如,您沒有最初的'