jQuery Validation Plugin: Validating Checkboxes with Different Names

前端 未结 3 1823
鱼传尺愫
鱼传尺愫 2021-02-03 16:38

I have a set of 4 checkboxes, all with different names, and require that at least 1 is checked.

I have set the class on all of them to \'require-one\'.



        
3条回答
  •  执笔经年
    2021-02-03 16:53

    I think @Anurag was on the right path. Check out this working version...

    http://jsfiddle.net/Y23ec/

    Same idea just a different way of doing it.

    jQuery(document).ready(function () { $.validator.addMethod('validate-checkbox-oneormore', function (value) { return $('.require-one:checked').size() != 0; }, 'need a value'); jQuery('#itemForm').validate({}); });

提交回复
热议问题