复选框状态(如果未选中)

Checkbox state if not checked

本文关键字:如果 状态 复选框      更新时间:2023-09-26

到目前为止,我有以下代码,但我遇到了一个问题,如果data-id尚未设置为checked,如何创建"状态"?

法典:

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

我在想这样的事情:

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

代码可能如下所示:

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