凡是从客户端向服务器发送数据,必须对数据做出验证(校验),在客户端过滤掉一些垃圾数据,减轻服务器的压力
onsubmit:当点击submit按钮时触发,有返回值,返回true表示提交表单,返回false不提交
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
function checkAccount(){
var account = document.getElementById("accountid").value;
if(account.length==0){
var accountMsg = document.getElementById("accountMsgId");
accountMsg.innerHTML = "账号不能为空!";
return false;
}
return true;
}
function save(){
if(checkAccount()&&checkPassword()){
return true;
}else{
return false;
}
}
</script>
</head>
<body>
<form method="get" onsubmit="return save()">
账号<input type="text" name="account" id="accountid" value="" onblur="checkAccount()"/>
<span id="accountMsgId"></span> <br/>
密码<input type="password" name="password"/> <br/>
<input type="submit" value="保存" />
</form>
</body>
</html>
it按钮时触发,有返回值,返回true表示提交表单,返回false不提交