<div class="rol">
手机:
<input type="text" value="" id="mobile">
<span class="tips" style="display: none">提示文字</span>
</div>
function checkAction(){
this.addStyle = function(){
$(this).addClass("focus");
};
this.removeStyle = function(){
$(this).removeClass("focus");
}
}
var checkItem = {
mobile : {
reg : "/^1[3|5][0-9]\d{4,8}$/",
error: "手机号格式错误",
tip:"请输入手机号用户密码找回"
},
email:{
reg:"",
error:"邮件格式错误",
tip:"请输入邮件地址"
}
};
$(function(){
// 手机验证
$('input[type=text]').bind('focus', function () {
checkAction.call(this);
this.addStyle();
});
$('input[type=text]').bind('blur', function () {
checkAction.call(this);
this.removeStyle();
var getId = this.id;//获得当前文本框ID
if ( this.value == '' ){
$(this).next('span').css('display','block');
} else {
if( !(checkItem.getId.reg.test(this.value)) ){//我的问题是:通过checkItem.mobile.reg可以读到mobile的json字典表的值,那么这里我想动态的判断是mobile这个ID表单项,进而通过checkItem.getId.reg也同样能读到mobile相应的键值,有劳大牛指导,谢谢
alert(checkItem.mobile.error);
} else {
alert("输入正确");
}
}
});
});
checkItem.getId.reg.test(this.value)
这句有问题
改成checkItem[getId].reg.test(this.value)
就可以了