8.7w+
社区成员
<body>
电子邮件:<input id="email" name="email" type="email" />
<input type="button" value="check" onclick="check();" />
<script type="text/javascript">
var check=function(){
if(document.getElementById("email").value.trim()==""){
alert("为空!");
}
else if(!document.getElementById("email").checkValidity()){
document.getElementById("email").setCustomValidity("电子邮件格式不对!");
}
else{
alert("allright!");
}
}
</script>
</body>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset='utf-8'>
<style>
</style>
</head>
<body>
<form action='#'>
电子邮件:<input id="email" name="email" type="email" />
<input type="submit" value="check" onclick="return check();" />
</form>
<script type="text/javascript">
var check=function(){
if(document.getElementById("email").value.trim()==""){
alert("为空!");
return false;
}
else if(!document.getElementById("email").checkValidity()){
document.getElementById("email").setCustomValidity("电子邮件格式不对!");
}
else{
alert("allright!");
}
}
</script>
</body>
</html>
需要form提交的