How to get values of <input type=“checkbox” /&g

2019-04-11 05:21发布

There are multiple <input type="checkbox" value="..." /> in the page.

I need to get each of the <input> that is checked to do some operation.

I'm using jQuery.

2条回答
姐就是有狂的资本
2楼-- · 2019-04-11 05:33
$("input[type=checkbox]:checked").each ( function() {
   alert ( $(this).val() );
});

or you can use

$("input:checkbox")

selector

If all the checkboxes are inside a container then you can narrow the selector by using

$("#containerID input[type=checkbox]:checked" )
查看更多
Anthone
3楼-- · 2019-04-11 05:45

You can also try this:

$(":checkbox :checked").each(function(){
  alert( $(this).val() );
});
查看更多
登录 后发表回答