重庆小面技术加盟:用javascript来提示要求输入

来源:百度文库 编辑:中科新闻网 时间:2024/04/29 03:19:26
我用javascript来判断是否为空
如果为空的话提交就出现提示
代码是这样
但是为什么为空的时候还是不出现提示呢?
各位帮帮我啊
<script language="text/javascript">
<!--
function check()
{
if (document.form1.name.value=='')
{
alert("请输入联系人姓名");
return false;
}

}
-->
</script>
<body>
<form id="form1" name="form1" method="post" action="" onsubmit="return check()">
<input type="text" name="name" />
<input type="submit" name="Submit" value="提交" onclick="check()" />
</form>
</body>

<script language=javascript>
<!--
function check()
{
if (form1.name.value=="")
{
alert("请输入联系人姓名");
form1.name.focus()
return false;
}

}
-->
</script>
<body>
<form id="form1" name="form1" method="post" action="" onsubmit="return check()">
<input type="text" name="name" >
<input type="submit" name="Submit" value="提交" >
</form>
</body>
这样就好了.你试一下吧.

现在好了.我又改了一下

<script language="text/javascript">
<!--
function check()
{
if (document.form1.linkname.value=='') //不要使用name
{
alert("请输入联系人姓名");
return false;
}

}
-->
</script>
<body>
<form id="form1" name="form1" method="post" action="" >
<input type="text" name="linkname" />
<input type="submit" name="Submit" value="提交" onclick="return check()" />
</form>
</body>