无法单击行并调用javascript函数?
我无法触发无法单击行并调用javascript函数?,javascript,jquery,Javascript,Jquery,我无法触发$(this).toggleClass('selected')。当我调试它时,只需跳过此事件。我如何确保它被选中 $('#contentChangesTable tr') .filter(':has(:checkbox:checked)') .addClass('selected') .end() .click(function (event) { $(this).toggleClass('selected'); if (
$(this).toggleClass('selected')内容表的代码>。当我调试它时,只需跳过此事件。我如何确保它被选中
$('#contentChangesTable tr')
.filter(':has(:checkbox:checked)')
.addClass('selected')
.end()
.click(function (event) {
$(this).toggleClass('selected');
if (event.target.type !== 'checkbox') {
$(':checkbox', this).attr('checked', function () {
return !this.checked;
});
}
});
您想使用prop
而不是attr
来设置选中状态
JSFiddle:
嗯,HTML…上面的代码是在$(document).ready()函数中吗?是的,它是在$(document).ready()函数中。您是在尝试更改行的选定类,还是也在尝试通过行单击选中行上的复选框?@tleish:代码执行后者(通过单击行切换复选框)。问题是使用attr
设置一个复选框
检查值(该值不起作用)。调试时,代码在之后跳过。单击(函数(事件){,它不会进入$(此)。toggleClass('selected'));我需要执行此命令才能拉动data@user2807977:请在实际HTML工作时更新我提供的JSFIDLE,但您的HTML不可用:)我为复选框NEW 1401297831778 SORTFOLDER comcast.CommunitU0000000000171721 38层测试添加了一个表和详细jquery
$(function () {
$('#contentChangesTable tr')
.filter(':has(:checkbox:checked)')
.addClass('selected')
.end()
.click(function (event) {
$(this).toggleClass('selected');
if (event.target.type !== 'checkbox') {
$(':checkbox', this).prop('checked', function () {
return !this.checked;
});
}
});
});