2012-03-02 53 views
2

我无法检查复选框,只有当我点击行,但我想单击它在两个方面。 这是我的方法,我用:jquery复选框无法点击

$("table tr").click(function(){ 
    var id=$(this).attr("id"); 
      //This is because i dont want first row to be able to select 
    if(typeof(id)!="undefined"){ 
     if($("#select-"+id).attr("checked")!="checked") 
      $("#select-"+id).attr("checked","checked"); 
     else 
      $("#select-"+id).removeAttr("checked"); 
    } 
}); 

而且在这里你可以实时观看它sabrio.eu5.org/admin.php 用户名:admin 密码:admin

回答

3

我最好的猜测是您的TR点击功能取消了被点击的复选框的默认行为。所以当你点击复选框时,它就像被点击两次。

尝试添加一个click事件复选框你这样......

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

您需要选择更改为适合您的HTML

See here for a working example

1

这会帮助

 $("table tr").click(function(){ 
     var checkbox = $(this).find(':checkbox'); 
     checkbox.attr('checked', !checkbox.attr('checked')); 
    });