0
我有一個模塊開發,其中我有一個父表和每行都有一個子表動態生成使用JSON數組通過使用jQuery的Ajax調用動態生成。
現在,我需要在每次將具有類「childtable」的子表插入到顯示子表ID的父錶行中時觸發警報。
我試圖用jQuery DOMNodeInserted事件來實現這個功能,它在IE中完全適用於我,但它在Chrome中不起作用。
我使用谷歌瀏覽器版本56.0.2924.87。
這段代碼如下所示。
Jquery DOMNodeInserted不工作在Chrome中,但在IE中工作
$('body').on('DOMNodeInserted', 'table.childtable', function(e) {
if (! $.fn.DataTable.isDataTable('#'+$(this).attr('id'))) {
var tab='#'+$(this).attr('id');
alert(tab); //fire id as alert
$('#'+$(this).attr('id')).DataTable({
"bSort" : false,
"scrollCollapse": true,
"searching": false,
"bInfo" : false,
"paging": false,
"columnDefs": [{
"targets": [ 0 ],
"visible": false
}]
});
$(tab).find("thead tr th").each(function(index1) {
index1 += 1;
$(tab).find("tbody tr td:nth-child(" + index1 + ")").attr("data-title", $(this).text());
});
}
});
請幫我傢伙...預先感謝您的時間。
'DOMNodeInserted'是過時[突變事件](https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Mutation_events)的一部分。改爲使用[突變觀察者](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver)。 – Teemu
我試圖讀取關於突變observers.but但我無法實現它..任何人都可以幫助我的代碼。 –