开发者

Deselect a checkbox

Im not sure why but for some reason when I click a td that has its checkbox already checked it does NOT deselect it.

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

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

    if(checkBox.attr('checked'))
        checkBox.attr('check开发者_JAVA百科ed', '');
    else
        checkBox.attr('checked', 'checked');
});


You want:

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


If you're using jQuery v1.6, you should be using .prop()

if(checkBox.prop('checked'))
    checkBox.prop('checked', false)
else
    checkBox.prop('checked', true);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜