jQuery验证仅适用于可见控件 [英] jquery validation only for visible controls

查看:80
本文介绍了jQuery验证仅适用于可见控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery验证进行必填字段验证.

I am using jquery validation for required field vaidation.

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

这也会触发隐藏的控件.

This fires for the controls which are hidden too.

例如:当用户以注册形式在How you find us?中选择Others选项时,需要填写其他选项的文本框.

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.

如何在jquery验证中做到这一点?

How to do it in jquery validation?

推荐答案

我以前没有使用过jQuery验证,但是根据文档中有一个忽略字段,您可以将jQuery选择器传递给该字段.通过使用:visible 选择器,您应该能够做到这一点.

I haven't used the jQuery validation before but according to the doco there's an ignore field that you can pass a jQuery selector to. By using the :visible selector you should be able to do this.

我相信这就是你所追求的

I believe this is what you're after

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

这篇关于jQuery验证仅适用于可见控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆