0

我正在使用 jQuery Datatables 列出用户,并使用 selectable 属性来选择和取消选择行。现在我有一个问题,我想让一行不可点击(即登录用户的行)......我该怎么做......任何帮助将不胜感激

$('#example tr').click( function() { 

}

如何为特定行禁用此功能?

4

3 回答 3

0

像这样的东西?(添加class="trDisable"到没有点击功能的行)

$('#example tr').not("#example tr.trDisable").click( function()

或者

$('#example tr.trDisable').click( function(e) {
    e.stopPropagation()
}
于 2012-07-04T12:48:50.570 回答
0

我想到了两种方法

1 each() 用法

$('#example tr').each(function(i) {
    if ( i === 2 ) {//this will select third tr
      $(this).off();
    }
});

2 eq() 用法 //我不确定这适用于表,也许 index() 会

var disabledRow = $('#example tr').eq(2);//this will deactive third row
if ( contition ) {
  disabledRow.off();
}

你可以阅读这些问题,它们应该会有所帮助

jquery禁用点击直到动画完全完成

如何用单击的对象的父对象定义条件?

于 2012-07-04T12:52:34.940 回答
0

我知道这是一个旧线程,但可能会帮助某人..

        $('#example').on('click', 'tbody tr', function () {
            var table = $('#example').DataTable();

            // Check if any rows are selected
            if (table.row(this, { selected: true }).any()) {
                // if condition here, if not valid
                if (!condition) table.row(this).deselect();
            }
        });
于 2015-08-21T08:54:27.763 回答