我做了什么
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.
问题: 当我点击新鲜时,它将变为选中状态。 然后我再次点击它并取消选中它。然后我继续这个过程并且它被卡住了。
答案 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");
}
});
});