javascript-如何找出导致jQuery相关消息“不赞成使用突变事件”的原因.改用MutationObserver”?
作者:互联网
在浏览器中加载典型页面时,出现以下消息:
Use of Mutation Events is deprecated. Use MutationObserver instead.
恰好引发此消息的行号为:jquery-3.2.1.js:5062:6
查看jQuery源代码,这是它包含的代码,其中令人讨厌的行是elem.addEventListener(type,eventHandle);.
// Init the event handler queue if we're the first
if ( !( handlers = events[ type ] ) ) {
handlers = events[ type ] = [];
handlers.delegateCount = 0;
// Only use addEventListener if the special events handler returns false
if ( !special.setup ||
special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
if ( elem.addEventListener ) {
elem.addEventListener( type, eventHandle );
# ^^^^^ the line that throws the Mutation Observer message
}
}
}
如何找到负责触发此消息的代码?
解决方法:
根据问题下的评论:
在您的代码库中搜索已弃用的DOM事件,即以下项的正则表达式:
DOMAttrModified | DOMAttributeNameChanged | DOMCharacterDataModified | DOMElementNameChanged | DOMNodeInserted | DOMNodeInsertedIntoDocument | DOMNodeRemoved | DOMNodeRemovedFromDocument | DOMSubtreeModified
它将向您显示触发过时事件的有害行.
标签:firefox,mutation-observers,javascript,jquery 来源: https://codeday.me/bug/20191111/2019314.html