开发者

How to get values of <input type="checkbox" /> that are checked?

开发者 https://www.devze.com 2022-12-12 11:01 出处:网络
There are multiple <input type=\"checkbox\" value=\"...\" /> in the page. I need to get each of the <in开发者_JAVA技巧put> that is checked to do some operation.

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

I need to get each of the <in开发者_JAVA技巧put> that is checked to do some operation.

I'm using jQuery.


$("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" )


You can also try this:

$(":checkbox :checked").each(function(){
  alert( $(this).val() );
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号