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但我无法实现它..任何人都可以帮助我的代码。 –