大佬教程收集整理的这篇文章主要介绍了jQuery:验证是否选中了多个复选框之一(不同的名称,使用jQuery Validation Plugin),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
// method for checking out checkBoxes for the form validation $.validator.methods.checkBoxes_checked = function(value,element,param) { return ($('#signup #checkBoxes input[type=checkBox]:checked').length > 0); }@H_404_14@…如果选中任何复选框,则返回true或false.我不想逐字逐句地使用上面的方法,因为这需要为每个复选框制定单独的规则,并且因为我有很多它们(20),这对我来说没有多大意义.
我唯一的问题是我不知道如何将它连接到我的验证调用中,因为我在页面上没有“单个”元素来绑定它(因为,我的所有其他验证规则都绑定到特定的单个元素,而我上面的扩展方法 – 实质上 – 与20个元素相关联).以下是我的验证调用现在的样子:
// validate the form $('#signup').validate({ rules: { 'bedrooms': { required: true },'maxrent': { required: true },'term': { required: true },'movedate': { required: true },'firstname': { required: true,minlength: 2 },'lastname': { required: true,minlength: 1,maxlength: 1 },'email': { required: true,email: true },'day_telephone': { required: true,digits: true,minlength: 10,maxlength: 10 } },errorPlacement: function(error,element) { error.css('display','none'); },highlight: function(element,errorClass) { $(element).fadeOut(function() { $(element).fadeIn(); }); $('label[for='+$(element).attr('name')+']').css('color','red'); },unhighlight: function(element,errorClass) { $('label[for='+$(element).attr('name')+']').css('color','black'); },onkeyup: false });@H_404_14@基本上,我希望表单本身检查(使用jQuery Validation Plugin),如果我的扩展方法在提交之前返回true.我该如何添加?
以上是大佬教程为你收集整理的jQuery:验证是否选中了多个复选框之一(不同的名称,使用jQuery Validation Plugin)全部内容,希望文章能够帮你解决jQuery:验证是否选中了多个复选框之一(不同的名称,使用jQuery Validation Plugin)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。