调用方式如下
var data={
fullName:$('.content').find('#fullNameTr').find('input').val(),
tel:$('.content').find('#telTr').find('input').val(),
email:$('.content').find('#emailTr').find('input').val(),
address:$('.content').find('#addressTr').find('input').val(),
send:$('.content').find('#sendTr').find('span[id=sendWay]').children('input:checked').attr('rel'),
sendArea:$('.content').find('#countryTr').find('select[name=district]').val()
}
/*************配置***************/
checkObj.checkConfig={
fullName:'isEmpty',
tel:'isEmpty',
email:'isEmail',
address:'isEmpty',
send:'isChecked',
sendArea:'isDefault'
}
/*************t提示函数************/
checkObj.showInfoFunc={
fullName:function(msg){
$('.content').find('#fullNameTr').find('span[class=showInfo]').html('<b class="red">'+msg+'</b>');
},
tel:function(msg){
$('.content').find('#telTr').find('span[class=showInfo]').html('<b class="red">'+msg+'</b>');
},
email:function(msg){
$('.content').find('#emailTr').find('span[class=showInfo]').html('<b class="red">'+msg+'</b>');
},
address:function(msg){
$('.content').find('#addressTr').find('span[class=showInfo]').html('<b class="red">'+msg+'</b>');
},
send:function(msg){
$('.content').find('#sendTr').find('span[class=showInfo]').html('<b class="red">'+msg+'</b>');
},
sendArea:function(msg){
$('.content').find('#countryTr').find('span[class=showInfo]').html('<b class="red">'+msg+'</b>');
}
}
/**************调用检查***************/
checkObj.check(data);
/*************确认是否有错误*************/
//alert(checkObj.rightMessage.lengths);
if(checkObj.hasErrors()){
alert('有错误');
}
本文介绍了一个简单的JavaScript表单验证库实现,包括空值检查、默认值检查、电子邮件格式验证等功能,并提供了完整的配置示例及错误提示显示方法。
7031

被折叠的 条评论
为什么被折叠?



