datatables 行点击事件

来源:互联网 发布:域名注册排行榜 编辑:程序博客网 时间:2024/06/09 19:04

这是官网上的方法,但是我用着没效果。

$(document).ready(function() {
    var table = $('#example').DataTable();
     
    $('#example tbody').on('click''tr'function () {
        var data = table.row( this ).data();
        alert( 'You clicked on '+data[0]+'\'s row' );
    } );
} );

这是我找到的另外一种方法,可以得到想要的效果

$(document).ready(function() {
    var table = $('#table tbody tr').DataTable();
     
    $('#table tbody tr').live('click', function() {
        var data = table.row( this ).data();
        alert( 'You clicked on '+data[0]+'\'s row' );
    } );
} );