不错的课程,学习了,收益很多力推:
基础篇:https://ke.qq.com/course/241103?saleToken=20026
高级篇:https://ke.qq.com/course/241105?saleToken=20027
<html>
<head><meta charset=utf-8 />
<!--引入jQuery-->
<!--coder:syl_ad@163.com 孙亚龙--->
<script src="jquery-1.7.2.min.js"></script>
<script>
var obj = {
res : true ,
nick_fun : function(o,tip){
if(this.res==true){
o.siblings("span").css("color","blue");
}else{
o.siblings("span").css("color","red");
}
o.siblings("span").html(tip);
}
}
$(function(){
var regex = new RegExp("^([\u4E00-\uFA29]){1,10}$");
var regmob = /(1[3458]\d{9},)*1[3458]\d{9}/g;
var regem = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
$(".name").blur(function(){
var v = $(this).val();
var re = regex.test(v);
obj.res = re;
re==true ? obj.nick_fun($(this),"姓名输入正确!") : obj.nick_fun($(this),"姓名为汉字!");
})
$(".email").blur(function(){
var v = $(this).val();
var re = regem.test(v);
obj.res = re;
re==true ? obj.nick_fun($(this),"邮箱输入正确!") : obj.nick_fun($(this),"邮箱输入格式不正确!");
})
$(".mobile").blur(function(){
var v = $(this).val();
var re = regmob.test(v);
obj.res = re;
re==true ? obj.nick_fun($(this),"手机号输入正确!") : obj.nick_fun($(this),"手机号输入有误!");
})
})
</script>
</head>
<body>
<form>
<div>姓名:<input type='text' name="name" class="name" /><span></span></div>
<div>邮箱:<input type='text' name="email" class="email" /><span></span></div>
<div>手机号:<input type='text' name="mobile" class="mobile" /><span></span></div>
<input type="button" value="点击" id="ck" />
</form>
</body>
</html>