简体   繁体   中英

jQuery.validator rule for not checked checkbox

I would like a jQuery.validator rule for a checkbox that is not checked. 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()

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.

$(".inputButton:checked")

That selector above will select all elements with a class of 'inputButton' and has the checked property true.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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