gpt4 book ai didi

javascript - 根据数据表中所有选中的复选框获取同级 td 值?

转载 作者:行者123 更新时间:2023-11-28 04:51:56 24 4
gpt4 key购买 nike

$('#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其他页面中选中的复选框。 。

这是表结构的示例片段: https://jsfiddle.net/30u4knrs/

最佳答案

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

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

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

关于javascript - 根据数据表中所有选中的复选框获取同级 td 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42848240/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com