我應用了下一個代碼來使得點擊時選中/取消選中一個子複選框。問題是,點擊複選框本身不起作用。我已經閱讀the post here並試圖申請e.stopPropagation();
,但仍然無法工作,有什麼想法?點擊一個li來檢查/取消選中一個複選框
$('#columnList li').click(function(){
var check = $(this).children();
var checkVal = check.attr('value');
var helper = $('.' + checkVal);
console.log(helper);
if(check.is(':checked')){
check.attr('checked','');
$.each(helper, function(i, e){
$(helper[i]).hide();
});
}else{
check.attr('checked','checked');
$.each(helper, function(i, e){
$(helper[i]).show();
});
}
});
$('input[type="checkbox"]').click(function(){
e.stopPropagation();
});
HTML是一個正常的ul
與兒童複選框。沒什麼特別的。
你能的休閒區與錶殼的jsfiddle,這樣我可以調試它?! –
Dosent有很大的意義...你也應該使用attr('checked',true/false)而不是檢查和空的:)試着用它上面的螢火蟲,看看我失敗的地方? –