<script language="javascript">
function checkform()
{
if(document.thisform.name.value)==""{
alert("please input your name");
document.thisform.name.focus();
return false;
}
return true;
}
</script>
<form action="reg.asp" method="post" name="thisform" onsubmit="return checkform()">
<input type="text" name="name">
<input type="submit" value="ok">
</form>
function checkform()
{
if(document.thisform.name.value)==""{
alert("please input your name");
document.thisform.name.focus();
return false;
}
return true;
}
</script>
<form action="reg.asp" method="post" name="thisform" onsubmit="return checkform()">
<input type="text" name="name">
<input type="submit" value="ok">
</form>
答案:
if(document.thisform.name.value)==""
这句里面的括号位置弄错了……
改成下面这样:
if(document.thisform.name.value=="")
就行了
全部代码:
<script language="javascript">
function checkform()
{
if(document.thisform.name.value==""){
alert("please input your name");
document.thisform.name.focus();
return false;
}
return true;
}
</script>
<form action="reg.asp" method="post" name="thisform" onsubmit="return checkform()">
<input type="text" name="name">
<input type="submit" value="ok">
</form>
这句里面的括号位置弄错了……
改成下面这样:
if(document.thisform.name.value=="")
就行了
全部代码:
<script language="javascript">
function checkform()
{
if(document.thisform.name.value==""){
alert("please input your name");
document.thisform.name.focus();
return false;
}
return true;
}
</script>
<form action="reg.asp" method="post" name="thisform" onsubmit="return checkform()">
<input type="text" name="name">
<input type="submit" value="ok">
</form>
本文介绍了一段JavaScript代码中关于表单验证的问题及修正方法。原本的代码在判断输入框是否为空时存在语法错误,文章提供了正确的代码实现,并展示了完整的HTML和JavaScript代码。
1394

被折叠的 条评论
为什么被折叠?



