Skip to main content
 首页 » 编程设计

javascript之如何在响应式显示的行上添加类

2026年09月08日3lori

我正在尝试在用户单击的行上添加一个类。为此,我使用 responsive-display 事件。

$(function () { 
    $('#people-waiting-send-up').DataTable().on('responsive-display', function (e, datatable, row, showHide, update) { 
        row.addClass('opened') 
    }); 
}); 

但是 row 不是 jQuery 对象,因此 addClass() 不起作用。我该怎么办?

请您参考如下方法:

使用row.index,我可以找到用户单击的行,并向其添加一个类:

$(function () { 
    $('#people-waiting-send-up').DataTable().on('responsive-display', function (e, datatable, row, showHide, update) { 
        $(datatable.row(row.index()).node()).addClass('opened'); 
    }); 
});