0
我有我的複選框的樣式標籤並隱藏了實際的複選框。檢查複選框點擊標籤時的狀態
<fieldset class='checkboxgroup'>
<div>
<input type='checkbox' id='item1' class='groupChkBox'>
<label for="item1">Julienne Carrots</label>
</div>
<div>
<input type='checkbox' id='item2' class='groupChkBox'>
<label for="item2">Lettuce Salad</label>
</div>
</fieldset>
$(".checkboxgroup label").click(function(){
if ($(this).is(':checked')) {
$("#boxofnouse").append("<div class='"+$(this).attr('id')+"'>hello world "+$(this).attr('id')+"</div>")
}
});
現在我的問題是如何檢查單擊標籤時是否選中複選框?
我試過使用,但沒有奏效。
var closestParentfieldset = $(this).closest("fieldset");
if ($(closestParentfieldset > input).is(':checked'))
這是+1在線基於CSS例如:檢查狀態:http://codepen.io/anon/pen/vhgqj/ –