2011-09-08 62 views
0

我应用了下一个代码来使得点击时选中/取消选中一个子复选框。问题是,点击复选框本身不起作用。我已经阅读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与儿童复选框。没什么特别的。

+0

你能的休闲区与表壳的jsfiddle,这样我可以调试它?! –

+0

Dosent有很大的意义...你也应该使用attr('checked',true/false)而不是检查和空的:)试着用它上面的萤火虫,看看我失败的地方? –

回答

4

尝试改变 -

$('input[type="checkbox"]').click(function(){ 
      e.stopPropagation(); 
     }); 

到 -

$('input[type="checkbox"]').click(function(e){ 
      e.stopPropagation(); 
     }); 
+0

我觉得很蠢......不敢相信我没有看到......谢谢! – Tsundoku

2

你应该尝试事件传递给函数

$('input[type="checkbox"]').click(function(e) { 
    e.stopPropagation(); 
}); 
相关问题