javascript文本框得到光标的问题

来源:百度知道 编辑:UC知道 时间:2024/05/17 01:13:09
<form name="form1" method="post" action="">
<label>
<input type="submit" name="Submit" value="提交" onClick="check()">
</label>
<label>sd
<input name="name" type="text" id="name">
</label>
<label>
<input name="pwd" type="text" id="pwd">
</label>
</form>
<script language="JavaScript">
function check()
{
if (document.form1.name.value=="")
{
alert("请输入姓名!");
document.form1.name.focus();
return false;
}
else if (document.form1.pwd.value=="")
{
alert("请输入密码!")
document.form1.pwd.focus()
return false
}
}

</script>

我的代码有什么错误为什么每次执行后文本框都不能得

<script language="JavaScript">
function check()
{
if (document.form1.name.value=="")
{
alert("请输入姓名!");
document.form1.name.focus();
return false;
}
else if (document.form1.pwd.value=="")
{
alert("请输入密码!");
document.form1.pwd.focus();
return false ;
}
}

</script>
<form name="form1" method="post" action="" onsubmit="return check()">
<label>
<input type="submit" name="Submit" value="提交"">
</label>
<label>sd
<input name="name" type="text" id="name">
</label>
<label>
<input name="pwd" type="text" id="pwd">
</label>
</form>

以上代码可以运行!
你的提交表单,所以表头要用