0
我对Jquery来说很新,而且我正试图找出脚本的问题。 该脚本检查并取消选中表格中的复选框。它还会删除TD上的类:product_select。当复选框未选中时移除TD上的课程
我的问题;标准它选择表中的第一个复选框。该复选框被选中并且td具有类'product_select'。一切都很好,但是当我点击这个复选框取消选中它时,TD上的类'product_select'不会被删除。它没有成功复选复选框,但它一直显示类“product_select”。这发生在表格有一个记录/ td /复选框时。
有没有人有一个想法,通过已经选择/选中的复选框从TD中删除类'product_select'?
希望我清楚。提前致谢。当该复选框被选中
$(document).ready(function() {
$("#emp_grid td").click(function(e) {
$("#emp_grid td").removeClass("product_select");
var $checkbox = $(this).find(':checkbox');
$("#emp_grid :checkbox").not($checkbox).removeAttr("checked");
if (e.target.type == "checkbox") {
// stop the bubbling to prevent firing the row's click event
e.stopPropagation();
$(this).filter(':has(:checkbox)').toggleClass('product_select', $checkbox.attr('checked'));
} else {
$checkbox.attr('checked', !$checkbox.attr('checked'));
$(this).filter(':has(:checkbox)').toggleClass('product_select', $checkbox.attr('checked'));
}
});
});
HTML代码:
<td class="product_select" colspan="3">
<input name="oplageservice" checked="checked" value="101_6" style="display:none;" type="checkbox"> € 0,01
</td>
HTML代码时,我取消选中该复选框:
<td class="product_select" colspan="3">
<input name="oplageservice" value="101_6" style="display:none;" type="checkbox"> € 0,01
</td>
(类 'product_select' 不被除去)
克雷格嗨,该帖子的HTML代码更新。 –
试试这个:更新后的答案以显示暗示 –
太棒了,那就是诀窍。非常感谢! –