我有一个带有 .on click 事件的代码,效果很好。但是,如果我将其更改为窗口加载或文档就绪,即使没有数据,它也会显示“行中数据”。我很困惑为什么它适用于点击事件而不是加载。评论将不胜感激,因为这让我发疯。非常感谢
这有效
$('#nirqst').on('click', 'tr', function () {
var table = $('#nirqst').DataTable();
//get the current row
var currentRow = $(this).closest("tr");
var col1 = currentRow.find(".dataTables_empty").html();
if((col1)=='No data available in table') {
console.log(col1);
table.buttons().disable();
} else {
console.log('data in row');
table.buttons().enable();
}
});
这不
$( window ).on( "load", function() {
var table = $('#nirqst').DataTable();
//get the current row
var currentRow = $(this).closest("tr");
var col1 = currentRow.find(".dataTables_empty").html();
if((col1)=='No data available in table') {
console.log(col1);
table.buttons().disable();
} else {
console.log('data in row');
table.buttons().enable();
}
});
繁星coding
繁星淼淼
相关分类