jQuery Validate Ignore elements with style

后端 未结 2 1853
天命终不由人
天命终不由人 2020-11-29 07:22

I am using jQuery validate for client side validation and I want to ignore any element that has the style=\"display: none\"

$(\"#myform\").valid         


        
相关标签:
2条回答
  • 2020-11-29 08:00

    http://api.jquery.com/hidden-selector/

    ":hidden"

    is what your looking for.

    Elements can be considered hidden for several reasons:

    • They have a display value of none.
    • They are form elements with type="hidden".
    • Their width and height are explicitly set to 0.
    • An ancestor element is hidden, so the element is not shown on the page.

    I feel this might be better.

    0 讨论(0)
  • 2020-11-29 08:08

    Note: As of version 1.9.0, ignore: ":hidden" is the default option, so it does not have to be set explicitly anymore.


    Use :hidden:

    Elements can be considered hidden for several reasons:

    • They have a display value of none.
    • They are form elements with type="hidden".
    • Their width and height are explicitly set to 0.
    • An ancestor element is hidden, so the element is not shown on the page.
    $("#myform").validate({
       ignore: ":hidden"
    });
    

    Update: for completeness, from the plugin's documentation:

    ignore
    Elements to ignore when validating, simply filtering them out. jQuery's not-method is used, therefore everything that is accepted by not() can be passed as this option. Inputs of type submit and reset are always ignored, so are disabled elements.

    0 讨论(0)
提交回复
热议问题