我希望我的表格行仅在编辑模式打开时才具有“可点击”类。通过元素检查,我可以看到这是有效的。如果我关闭编辑模式,它会成功删除“可点击”类。
如果表行具有可单击的类,它将在单击表行时单击其复选框。
这也有效,但是当我关闭编辑模式时,我仍然可以单击表格行,并通过这样做,还可以选中复选框。
如果您发现我忽略的内容,请告诉我。
function clickableTableRow(isClickable) {
if (isClickable) {
$(tableBody).find('tr').each(function () {
$(this).addClass("clickable");
$(this).click(function () {
$(this).find('input[type=checkbox]').click();
});
})
} else {
$(tableBody).find('tr').each(function () {
$(this).removeClass("checked").removeClass("clickable");
$(this).find('input[type=checkbox]').prop("checked", false);
})
}
}
所以为了澄清,在元素检查中我可以看到它做了所有应该做的事情,所以我认为问题在于我在单击表格行时单击复选框的函数
最佳答案
使用.off()
$(this).off('click');
The
off()
Method in jQuery is used to remove event handlers attached with theon()
method -or the.click()
method. Theoff()
method brings a lot of consistency to the API and it replaceunbind()
,die()
andundelegate()
methods.
关于javascript - 为什么jquery不响应我的条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60074291/