繁体   English   中英

无法单击一行并调用javascript函数?

[英]Unable to Click a row and call javascript function?

我无法触发$(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: http : //jsfiddle.net/TrueBlueAussie/RV46q/

$(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;
            });
        }
    });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM