我在其标签中有一个复选框输入。我读了这个没问题。我还在其中嵌套了第二个复选框,用于解决绝对定位问题。我隐藏了输入,因此标签是点击处理程序。如果单击 label-1,我想让 label-2 可见,但它们在许多列表中。
小提琴:http: //jsfiddle.net/kirkbross/tfKva/6/
<li>
<label class="label-1">Label #1 (parent label so to speak)
<input type="checkbox" class="checkbox-1"/> // when this is checked (its label clicked) make label-2 visible
<label class="label-2">Label #2
<input style="visibility:hidden;" class="checkbox-2" />
</label>
</label>
</li>
这是我的代码不起作用:
$("label").click(function() {
$("input:checkbox").each(function() {
if ($(this).prop("checked")) {
$(this).next('.label-2').show(); // can't figure out how to get at the second "nested" label
} else {
$(this).next('.label-2').hide();
}
});
});