简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM