2011-07-03 174 views
0

我不知道爲什麼,但由於某種原因,當我點擊一個td,其複選框已經被選中時,它不會取消選擇它。取消選擇一個複選框

$('table tr').click(function() { 

    checkBox = $(this).children('td').children('input[type=checkbox]'); 

    if(checkBox.attr('checked')) 
     checkBox.attr('checked', ''); 
    else 
     checkBox.attr('checked', 'checked'); 
}); 

回答

6

你想:

if(checkBox.attr('checked')) 
     checkBox.removeAttr('checked'); 
    else 
     checkBox.attr('checked', 'checked'); 
+0

感謝u爲響應。 –

0

如果你正在使用jQuery V1.6,你應該使用.prop()

if(checkBox.prop('checked')) 
    checkBox.prop('checked', false) 
else 
    checkBox.prop('checked', true); 
相關問題