我有一個帶有 .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(); }});
窗口加載未顯示正確的 else 消息
喵喵時光機
2021-11-18 15:52:33