【问题标题】:Get sibling td values based on all checked checkboxes in a datatable?根据数据表中的所有选中复选框获取同级 td 值?
【发布时间】:2017-03-17 02:35:42
【问题描述】:
$('#save-board-assignees').click(function ()
{
    $('#board_assignee_table_wrapper input[type="checkbox"]:checked').each(function(i, td_e)
    {
        console.log('Found checked checkbox');
        var assignee_id = 0;
        var team_id = 0;
        var assignee_holder = [];

        assignee_id = $(this).closest('td').next().attr('id');
        assignee_name = $(this).closest('td').next().html();
        team_id = $(this).closest('td').next().next().attr('id');

        console.log('Assignee name: ' + assignee_name);
        console.log('Team id: ' + team_id);
        console.log('Assignee id: ' + assignee_id);

        assignee_holder.push(assignee_id, assignee_name);
        board_assignees.push(assignee_holder);
    });
}

此代码仅获取选中页面上选中复选框的兄弟<td>(受让人姓名、团队ID、受让人ID)的值。它不会在DataTable 的其他页面中选择选中的复选框。

这是表结构的示例 sn-p: https://jsfiddle.net/30u4knrs/

【问题讨论】:

  • @KScandrett 这样可以吗? jsfiddle.net/30u4knrs/1
  • 你在使用datatables.net吗?
  • @KScandrett 是的
  • @KScandrett 谢谢,我会在那里尝试解决方案
  • 发布了比我提供的链接更好的解决方案

标签: javascript jquery html checkbox datatable


【解决方案1】:

使用.$() (https://datatables.net/reference/api/%24()) 访问所有表格元素(不仅仅是当前可见的元素):

var table = $('#example').DataTable();

table
   .$('input[type="checkbox"]:checked')
   .each(function(i, td_e) { ...

【讨论】:

  • 没想到这么简单。谢谢!
猜你喜欢
  • 1970-01-01
  • 2016-10-14
  • 1970-01-01
  • 2016-06-18
  • 2011-08-14
  • 2016-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多