码迷,mamicode.com
首页 > 其他好文 > 详细

失焦验证

时间:2016-06-01 23:08:05      阅读:544      评论:0      收藏:0      [点我收藏+]

标签:

<body>
账号:<input type="text"><span style="color: red"></span>
<p>密码:<input type="password"><span style="color: red"></span></p>
<p><button>登陆</button></p>

<script>
var usernameEle = document.getElementsByTagName("input")[0],
passwordEle = document.getElementsByTagName("input")[1],
usernameWarnEle = document.getElementsByTagName("span")[0],
passwordWarnEle = document.getElementsByTagName("span")[1],
btnEle = document.getElementsByTagName("button")[0];

usernameEle.onblur = function() {
var usernameVal = usernameEle.value;
//全部清空
usernameWarnEle.innerHTML = "";
if (!/^[\u4e00-\u9fa5]|[A-z]|[0-9]{4,20}$/.test(usernameVal)){
usernameWarnEle.innerHTML = "格式错误!";
}else{
usernameWarnEle.innerHTML = "格式正确!";
}

//判断
if (usernameVal === "") {
usernameWarnEle.innerHTML = "账号不能为空!";
}
}
passwordEle.onblur = function() {
var passwordVal = passwordEle.value;
//全部清空
passwordWarnEle.innerHTML = "";

//判断
if (passwordVal === "") {
passwordWarnEle.innerHTML = "密码不能为空!";
}
}

</script>

</body>

失焦验证

标签:

原文地址:http://www.cnblogs.com/huangmingkedeboke/p/5551165.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!