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

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

I have this not so many checkboxes:

 
4条回答
  •  醉酒成梦
    2020-12-24 15:08

    This can be done using .map, though in this case it is not really different from using .each:

    $(":checkbox").change(function() {
        var notChecked = [], checked = [];
        $(":checkbox").map(function() {
            this.checked ? checked.push(this.id) : notChecked.push(this.id);
        });
        alert("checked: " + checked);
        alert("not checked: " + notChecked);
    });
    

    You can test it here.

提交回复
热议问题