如何使用jQuery循环遍历未指定数量的复选框?

Met*_*uru 4 checkbox jquery

我需要循环遍历一个包含未知数量的复选框的div并获取已检查的复选框的值,如何使用jQuery执行此操作?我想它应该发生在任何复选框的更改.

mar*_*cgg 8

做就是了:

<div id="blah"> 
  <input type="checkbox" class="mycheckbox" />
  <input type="checkbox" class="mycheckbox" />
  <input type="checkbox" class="mycheckbox" />
</div>

$("#blah .mycheckbox").each(function(){
  alert(this + "is a checkbox!");
});
Run Code Online (Sandbox Code Playgroud)


End*_*der 5

尝试:

<div id="blah"> 
  <input type="checkbox" class="mycheckbox" />
  <input type="checkbox" class="mycheckbox" />
  <input type="checkbox" class="mycheckbox" />
</div>

$("#blah .mycheckbox:checked").each(function(){
  alert($(this).attr("value"));
});
Run Code Online (Sandbox Code Playgroud)