<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>表單驗(yàn)證</title>
</head>
<body>
<form action="" method="get" onsubmit="return checkForm()">
<div align="center">
<h2>用戶登錄</h2>
<hr width="30%"/>
賬號(hào):<input type="text" name="userid" id="userid" value="" /><br /><br />
密碼:<input type="password" name="password" id="password" value="" /><br /><br />
<input type="submit" value="用戶登錄" />
</div>
</form>
</body>
<script type="text/javascript">
//驗(yàn)證表單
function checkForm(){
//賬號(hào)的信息
var userid = document.getElementById("userid");
//密碼的信息
var password = document.getElementById("password");
if(userid.value.length == 0){
alert("賬號(hào)不能為空");
return false;
}
if(password.value.length == 0){
alert("密碼不能為空");
return false;
}
}
</script>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>表單驗(yàn)證</title>
</head>
<body>
<form action="" method="get" id="f1">
<div align="center">
<h2>用戶登錄</h2>
<hr width="30%"/>
賬號(hào):<input type="text" name="userid" id="userid" value="" /><br /><br />
密碼:<input type="password" name="password" id="password" value="" /><br /><br />
<input type="submit" value="用戶登錄" />
</div>
</form>
</body>
<script type="text/javascript">
window.onload = function(){
document.getElementById("f1").onsubmit = function(){
//賬號(hào)的信息
var userid = document.getElementById("userid");
//密碼的信息
var password = document.getElementById("password");
if(userid.value.length == 0){
alert("賬號(hào)不能為空");
return false;
}
if(password.value.length == 0){
alert("密碼不能為空");
return false;
}
}
}
</script>
</html>
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者