取消选中一个复选框

Jef*_*son 0 jquery

我不知道为什么,但由于某种原因,当我点击已经检查了其复选框的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');
});
Run Code Online (Sandbox Code Playgroud)

Dex*_*Dex 6

你要:

   if(checkBox.attr('checked'))
        checkBox.removeAttr('checked');
    else
        checkBox.attr('checked', 'checked');
Run Code Online (Sandbox Code Playgroud)