JQUERY: get the id's of the checked and not checked checkBox

前端 未结 4 2059
你的背包
你的背包 2020-12-24 14:12

I have this not so many checkboxes:

 
4条回答
  •  盖世英雄少女心
    2020-12-24 15:08

    I would do this something like this:

    var all, checked, notChecked;
    all = $("input:checkbox");
    checked = all.filter(":checked");
    notChecked = all.not(":checked)");
    

    After that you can use jQuery.map to get the ids of each collection.

    var checkedIds = checked.map(function() {
        return this.id;
    });
    
    var notCheckedIds = notChecked.map(function() {
        return this.id;
    });
    

提交回复
热议问题