jQuery validate plugin on DIV

前端 未结 5 1924
太阳男子
太阳男子 2020-11-29 08:29

I am trying to use the validate plugin on a div as shown in the answer to this question:



        
5条回答
  •  温柔的废话
    2020-11-29 08:29

    This isn't the answer you want to hear, but the other answer is incorrect (it may have been right when it was posted, but there have been several major jQuery validation plugin changes since then).

    The validation plugin is (currently) designed to work on a

    , and only on a . You can also note that all of the plugin documentation references a form, not any other generic container.

    The plugin itself keeps track of validator.currentForm internally, which refers to the this of the passed in selector, getting .elements, etc off that...it's really not going to work any other way, not the way the current version's written.

    The overall solution/alternative approach here: call .validate() on the element (the jQuery wrapper for it rather) directly, not any other container. If you need to divide your use

    elements, possibly using the ignore: ':hidden' option in .validate() if you don't want to validate input fields that aren't visible to the user.

提交回复
热议问题