2012-03-02 80 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')); 
    });