【发布时间】:2011-09-08 09:47:21
【问题描述】:
我应用了下一个代码来使 li 在单击时选中/取消选中子复选框。问题是当单击复选框本身时它不起作用。我已经阅读了the post here 并尝试应用e.stopPropagation(); 但仍然无法正常工作,有什么想法吗?
$('#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) 而不是 checked 和 empty :) 尝试在其上使用 firebug,看看我在哪里失败了?跨度>