jquery validation only for visible controls

2021/01/31 02:41 · jquery ·  · 0评论

I am using jquery validation for required field vaidation.

$("#registerform").validate();

This fires for the controls which are hidden too.

For ex.: When the user selects Others option in How you find us? in register form, its required to fill the textbox for others option.

But this fires even when the control is hidden.

How to do it in jquery validation?

我之前没有使用过jQuery验证,但是根据doco的介绍,您可以将jQuery选择器传递给ignore字段。通过使用:visible选择器,您应该可以做到这一点。

我相信这就是你所追求的

$("#registerform").validate({ignore:":not(:visible)"});

You may try to add :visible to the selector itself:

$("#registerform :visible")

请也尝试这种方式

 if ($(#registerform).is(":visible")) {
      $(#registerform).validate();
  }
本文地址:http://jquery.askforanswer.com/jquery-validation-only-for-visible-controls.html
文章标签: ,  
版权声明:本文为原创文章,版权归 admin 所有,欢迎分享本文,转载请保留出处!

文件下载

老薛主机终身7折优惠码boke112

上一篇:
下一篇:

评论已关闭!