我想要从数据表中提取表的ID,而不指定函数中的表名。例如:我不需要指定var tableName = $('#myTable').attr(' name '),而是想在不编写#myTable的情况下提取表名
$(document).ready(function() {
$('#myTable').DataTable( {
dom: 'Bfrtip',
buttons: [
{ extend : 'collection',
text : '<i class="fa fa-bars">buttons</i>',
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print',
{
text: 'Report Issue',
action: function ( e, dt, node, config ) {
reportIssue(e, dt, node, config);
}
}
]
}]
} );
// e - the button click event
// dt - the datatable object
// node - button node
// config - the button's config (e.g. 'text')
function reportIssue(e, dt, node, config) {
var tableName = $('#myTable').attr('name');
alert( 'The "' + config.text + '" button was clicked\n'
+ 'for the "' + tableName + '" table.' );
}
});发布于 2020-04-20 20:03:27
看看https://datatables.net/reference/api/%24.fn.dataTable.tables()
$.fn.dataTable.tables().forEach(function(dt) {
console.log( dt.id ) //in your case myTable
})如果你只有一张桌子或者知道该找什么
console.log( $.fn.dataTable.tables()[0].id ) //myTablehttps://stackoverflow.com/questions/61327453
复制相似问题