简体   繁体   English

如何获得 <input type=“checkbox” /> 被检查?

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

There are multiple <input type="checkbox" value="..." /> in the page. 页面中有多个<input type="checkbox" value="..." />

I need to get each of the <input> that is checked to do some operation. 我需要获取每个被检查以执行某些操作的<input>

I'm using jQuery. 我正在使用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() );
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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