jQuery: Accessing table rows of second and further pages of a datatable

前端 未结 2 667
长发绾君心
长发绾君心 2021-01-14 16:30

I am retrieving table row data like this from a HTML table.

var descriptions = [];

var testRows = $(\'#tbl\').find(\'tbody\').find(\'tr\');
$this = $(this);         


        
2条回答
  •  说谎
    说谎 (楼主)
    2021-01-14 17:07

    If you use an older version of jQuery you can use .live() function. With newer version you should switch to .on(). But you can always make a function from what you wrote:

    function example() {
        var testRows = $('#tbl').find('tbody').find('tr');
        $this = $(this);
    
        testRows.each(function () {
            var description = $this.find('[id^="Desc"]').text();
            descriptions.push(description);
        }
    }
    

    and run it every time you operate on your table:

    function removeTr() {
        $('tr').remove();
        example();
    }
    

提交回复
热议问题