简体   繁体   English

jQuery.validator规则未选中复选框

[英]jQuery.validator rule for not checked checkbox

I would like a jQuery.validator rule for a checkbox that is not checked. 我想要一个未选中复选框的jQuery.validator 规则 Below is what I have if the checkbox is checked, but I can't figure out the syntax for a rule for not checked. 如果选中该复选框,下面是我所拥有的,但是我无法弄清未选中规则的语法。 Any help would be appreciated. 任何帮助,将不胜感激。 Thanks! 谢谢!

rules: {
    sbPhone: {
         required: "#sbPhoneMe:checked",
         phoneUS: true
    },

Try :not() 尝试:not()

rules: {
    sbPhone: {
         required: "#sbPhoneMe:not(:checked)",
         phoneUS: true
    },

I am unfamiliar with that syntax, but jQuery has a selector ":checked" you can use to determine if an element is checked or not. 我不熟悉该语法,但是jQuery具有选择器“:checked”,您可以使用该选择器来确定是否检查了元素。

$(".inputButton:checked")

That selector above will select all elements with a class of 'inputButton' and has the checked property true. 上面的选择器将选择所有具有“ inputButton”类的元素,并且其checked属性为true。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM