87,955
社区成员
![](https://csdnimg.cn/release/cmsfe/public/img/topic.427195d5.png)
![](https://csdnimg.cn/release/cmsfe/public/img/me.40a70ab0.png)
![](https://csdnimg.cn/release/cmsfe/public/img/task.87b52881.png)
![](https://csdnimg.cn/release/cmsfe/public/img/share-circle.3e0b7822.png)
<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提交的