<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style media="screen">
#email{
width: 250px;
background-color: rgb(173, 182, 191);
}
</style>
</head>
<body>
<div class="">
请输入邮箱:<input id="email" type="text" name="" value="" placeholder="请输入邮箱:例如123231@qq.com" required>*<br>
</div>
<script type="text/javascript">
//封装获得id
function $id(id){
return document.getElementById(id);
}
//获得邮箱
$id("email").onblur=function () {
var regExp=/^[0-9a-zA-Z_]+[@][0-9a-zA-Z_]+(.[a-zA-Z]{1,2})$/;
if (regExp.test(this.vale)) {
// this.setAttribute('backgroung-color','greed');
// this.style.backgroundColor = "green";
this.style.cssText='background-color:green;width:10px;'
}
else {
// this.setAttribute('backgroung-color','red');
// this.style.backgroundColor = "red";
this.style.cssText='background-color:red;width:10px;'
}
}
</script>
</body>
</html>
瑜伽兔子
相关分类