多选复选框选中的问题

时间:2014-06-23 14:03:49

标签: javascript php jquery html checkbox

我做了什么

 1. create array of checkboxes with unique numeric ID 
 2. on click of <td>(with unique numeric ID also ) i checked-unchecked the checkbox 
 3. I used jQuery to check-uncheck logic.

问题:      当我点击新鲜时,它将变为选中状态。      然后我再次点击它并取消选中它。然后我继续这个过程并且它被卡住了。

http://jsfiddle.net/5zQFe/

2 个答案:

答案 0 :(得分:0)

尝试:

.prop("checked", false);

.prop("checked", 'checked');

取代.attr(...)

答案 1 :(得分:0)

是的,我只是确保声明输入而不是TD的ID:

$(document).ready(function () {
    $('.tdbox').click(function () {
        var tdID = $(this).attr('id');
        if ($(this).attr('id') == -1) {
            return false;
        }
        var inp = $(this).find("input[id=" + tdID + "]");

        if (inp.is(':checked')) {
            $(inp).prop("checked", false);
            $(this).css('background-color', "");
        } else {
            $(inp).prop("checked", true);
            $(this).css('background-color', "yellow");
        }
    });
});