简体   繁体   中英

Checkbox state if not checked

I so far have the following code but I am having an issue and thats how can create the "state" if the data-id has not been set as checked ?

Code:

        $("input[type='checkbox']").each(function(){
             if ($(this).is(":checked")) checkbox.push($(this).data("id"))
        })

I was thinking something like this:

    $("input[type='checkbox']").each(function(){
             if ($(this).is(":checked")) checkbox.push($(this).data("id"))
             {
                $state = 1; 
             }else{
                $state = 0;
             }
        })

The code might be like:

    $("input[type='checkbox']").each(function(){
         if ($(this).is(":checked")) 
         {
            checkbox.push($(this).data("id"));
            $state = 1; 
         }else{
            $state = 0;
         }
    })

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