每行都有数据获取按钮

问题描述 投票:0回答:1

我在一个datatable的 "action "列中的每一行有2个按钮。不同行的每个按钮都有相同的类,但不同的data-id,我想通过jquery模拟按钮的点击,点击每行中的一个按钮。我想从jquery中点击每行中的一个按钮来模拟按钮的点击。我试图在datatable上循环并得到每行的按钮,但没有成功。

请检查ss。

enter image description here

$('#apply-all').on('click', function (e) {
            var table  = $('.mydatatable').DataTable();
            table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
                  var data = this.data(); // able to fetch the data.
                  //how to feth the button on this row?
            } );
        });
javascript html jquery dom datatable
1个回答
1
投票

你可以使用 节点 功能 .node() 函数来获取所选行的元素。然后你就可以用jQuery把它包装起来,像这样执行jQuery操作。

    $('#apply-all').on('click', function (e) {
        var table  = $('.mydatatable').DataTable();
        table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
              var data = this.data(); // able to fetch the data.
              var row = this.node();
              var rowJqueryObject = $(row);
              //or
              $(row).find('button'); //will return all buttons in that row
        } );
    });
© www.soinside.com 2019 - 2024. All rights reserved.