jQuery Validation using the class instead of the name value

前端 未结 7 1293
清酒与你
清酒与你 2020-11-29 00:09

I\'d like to validate a form using the jquery validate plugin, but I\'m unable to use the \'name\' value within the html - as this is a field also used by the server app. Sp

7条回答
  •  野性不改
    2020-11-29 01:04

    Another way you can do it, is using addClassRules. It's specific for classes, while the option using selector and .rules is more a generic way.

    Before calling

    $(form).validate()
    

    Use like this:

    jQuery.validator.addClassRules('myClassName', {
            required: true /*,
            other rules */
        });
    

    Ref: http://docs.jquery.com/Plugins/Validation/Validator/addClassRules#namerules

    I prefer this syntax for a case like this.

提交回复
热议问题