html 表单 dom 注意跟表单的name值一致

html 表单 dom   注意跟表单的name值一致
<script type="text/javascript">
function checkForm()
{
    var theForm = document.form1;
    if(theForm.username.value=="")    //html 表单 dom   注意跟表单的name值一致
    {
        window.alert("用户名不能为空");
        return false;
    }else if(theForm.userpwd.value.length==0)
    {
        window.alert("密码不能为空");
        return false;
    }else
    {
        window.alert("验证通过");
        return true;
    }
}
</script>
</head>
<body>
<form name="form1" method="get" action="login.php" onsubmit="return checkForm()">
用户名:<input type="text" name="username" />
密码:<input type="password" name="userpwd" />
<input type="submit" value="提交表单" />
</form>

 

posted @ 2016-01-27 14:28  gyz418  阅读(223)  评论(1)    收藏  举报