Declaring jQuery Validate plugin rules — attribute vs. class vs. code

前端 未结 4 1717
眼角桃花
眼角桃花 2020-12-09 15:45

In the examples for the jQuery Validate plugin, I see three different approaches to declaring validation rules:

  • CSS Classes -- e.g.
4条回答
  •  离开以前
    2020-12-09 16:30

    From the documentation http://jqueryvalidation.org/rules:

    There are several ways to specify validation rules.

    • Validation methods without parameters can be specified as classes on the element (recommended)
    • Validation methods with parameters can be specified as attributes (recommended)
    • Both can be specified as metadata using the metadata plugin [[[note that this is deprecated, so the docs appear to be out of date a bit]]]
    • Both can be specified using the rules-option of the validate()-method

    https://stackoverflow.com/a/14380401/749227 has some additional useful information.

    I prefer using the 'required' attribute over a class, though. I don't find this sort of native attribute support it directly referenced in the documentation, but since it seems like screen-readers would find it more useful than class="required" I go with that in this one case.

    As an aside, I'd love to see what other native attributes are respected by the plugin. And info on which of them are picked up by ADTs.

提交回复
热议问题