我需要循环遍历一个包含未知数量的复选框的div并获取已检查的复选框的值,如何使用jQuery执行此操作?我想它应该发生在任何复选框的更改.
做就是了:
<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)
尝试:
<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)