我一直致力于javascipt功能,以推迟'使用观察者执行节点X.这在Chrome和IE上完全正常,但在Firefox中无法正常运行。不确定这是兼容性问题还是错过了几行代码。
//观察者函数
function observer(callback) {
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (!mutation.addedNodes) return;
for (var i = 0; i < mutation.addedNodes.length; i++) {
var node = mutation.addedNodes[i]
if($(node).hasClass('X')) {
callback();
observer.disconnect();
}
}
});
});
observer.observe(document, { childList: true, subtree: true, attributes: false, characterData: false });
}
function observerFallback(callback) {
var observerFallbackEvent = function(e) {
if(e.target.tagName === 'OBJECT' && $(e.target).hasClass('X')) {
callback();
document.removeEventListener('DOMNodeInserted', observerFallbackEvent);
}
}
document.addEventListener('DOMNodeInserted', observerFallbackEvent);
}