HTML5--表单验证
2018-10-28 本文已影响0人
废废_siri
checkValidity
校验内容是否合法。
<html>
<head>
<title>
checkValidity demo
</title>
<meta charset="UTF-8">
</head>
<body>
<script>
function check(){
var email = document.getElementById("email");
if(email.value == ""){
alert("请输入email!");
return false;
}else if(!email.checkValidity()){
alert("请输入正确的email地址");
return false;
}
}
</script>
<!--novalidate为true时,取消表单默认验证-->
<form novalidate="true">
<label for="email">邮箱:</label>
<input id="email" type="email" name="email"><br/>
<input type="submit" value="提交" onclick="check()">
</form>
</body>
</html>