我一直在尝试允许一个复选框检查多个嵌套 div 中的其他复选框,但它不起作用。我找不到复选框的 Dom 路径。这是html:
<div class="box span12 " id="Clarendon_region">
<div class="box-content">
<div class="row-fluid">
<div class="span3 ">
<span>
<div class="checker">
<span>
<input type="checkbox">
</span>
</div>
</span> Branch 115
</div>
</div>
</div>
</div>
这是jQuery:
$('span input').click(function(e){
var elIDSplit = e.target.id.split("_");
if(elIDSplit[0] == "chk" && elIDSplit[2] == "region") {
//alert(e.target.id);
status = $(e.target).attr("checked");
if (status == undefined) {
status = false;
}
$(elIDSplit[1]+"_"+elIDSplit[0]+" .box-content .row-fluid .span3 span .checker span input:checkbox.friends").attr("checked",status);
}
});
更新:这是通过给输入一个类名然后使用这个来解决的:
$(".allbranches_" + elIDSplit[1]).attr('checked', status);
//does not work without this line since uniform is responsible for styling the checkbox
$.uniform.update();