js代码

<script type="text/javascript"> function check(){ var nameValue=window.document.getElementById("name").value; var pasValue=window.document.getElementById("password").value; if (nameValue == "") { window.alert("帐号不能为空!"); return false; }else if (pasValue == "") { window.alert("密码不能为空!"); return false; } return true; } </script>

html代码

<form action="1.php" method="post" onsubmit="return check()"> <p>帐号: <input id="name" type="text" name="name" /></p> <p>密码: <input id="password" type="text" name="password" /></p> <input type="submit" value="登录"/> </form>
如果觉得我的文章对你有用,请随意赞赏