简体   繁体   中英

how to use is()

How to refactor the follow to put NOT is(":checked") syntax, instead put the codes being executed in the else block?

if ($(this).is(":checked")) {
    // do nothing
}
else {
    // To do here
}

Thanks for all the help.

You would add a negation ( ! ) to it, like this:

if (!$(this).is(":checked")) {

But you can just use the checked DOM property directly here, which is much faster:

if (!this.checked) {

Do you want this, or am I missing something?

if( $(this).is(":checked") == false) 
{
    // To do here
}

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