请教下高手,为什么我的javascript的这段代码不能正常运行啊
发布网友
发布时间:2024-10-22 04:29
我来回答
共5个回答
热心网友
时间:2024-10-22 06:24
确实
另外还有几处,修改后如下:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Examle</title>
<script type="text/javascript">
function buttonCheckForm_onclick()
{
var form1 = document.myForm;
if(form1.textName.value == "" || form1.textAge.value == "")
{
alert("PLease complete the form");
if(form1.textName.value == "")
{
form1.textName.focus();
}
else
{
form1.textAge.focus();
}
}
else
{
alert("Thanks for completing the form" + form1.textName.value);
}
}
function textAge_onblur()
{
var textAge = document.myForm.textAge;
if (isNaN(textAge.value) == true)
{
alert("Please enter a valid age");
textAge.focus();
textAge.select();
}
}
function textName_onchange()
{
window.status = "Hello" + document.myForm.textName.value;
}
</script>
</head>
<body>
<form action="" name="myForm">
Please enter the following details:
<p>
Name:
<br/>
<input type="text" name="textName" onchange="textName_onchange()" />
</p>
<p>
<input type="text" name="textAge" onblur="textAge_onblur()" size="3" maxlength="3" />
</p>
<p>
<input type="button" value="Check Details" name="buttonCheckForm" onclick="buttonCheckForm_onclick()" />
</p>
</form>
</body>
</html>
热心网友
时间:2024-10-22 06:30
首先,函数后跟{而不是[,其次,判断用==而不是=。谢谢
热心网友
时间:2024-10-22 06:32
function buttonCheckForm_onclick()
[
不是用 [ 这个吧。
热心网友
时间:2024-10-22 06:28
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Examle</title>
<script type="text/javascript">
function buttonCheckForm_onclick()
{
var form1 = document.myForm;
if(form1.textName.value == "" || form1.textAge.value == "")
{
alert("PLease complete the form");
if(form1.textName.value == "")
{
form1.textName.focus();
}
else
{
form1.textAge.focus();
}
}
else
{
alert("Thanks for completing the form" + form1.textName.value);
}
}
function textAge_onblur()
{
var textAge = document.myForm.textAge;
if (isNaN(textAge.value) == true)
{
alert("Please enter a valid age");
textAge.focus();
textAge.select();
}
}
function textName_onchange()
{
window.status = "Hello" + document.myForm.textName.value;
}
</script>
</head>
<body>
<form action="" name="myForm">
Please enter the following details:
<p>
Name:
<br/>
<input type="text" name="textName" onchange="textName_onchange()" />
</p>
<p>
<input type="text" name="textAge" onblur="textAge_onblur()" size="3" maxlength="3" />
</p>
<p>
<input type="button" value="Check Details" name="buttonCheckForm" onclick="buttonCheckForm_onclick()" />
</p>
</form>
</body>
</html>
可以了,你试一试可以不
热心网友
时间:2024-10-22 06:30
完全赞同西溪南凡风 的意见。