MutationObserver
方法
disconnect()
tells the observer to stop watching for mutations.
The observer can be reused by calling its
observe()
method again.
mutationObserver.disconnect()
None.
undefined
.
注意: All notifications of mutations that have already been detected ,但 not yet reported to the observer, are discarded.
If the element being observed is removed from the DOM, and then subsequently released by the browser's garbage collection mechanism, the
MutationObserver
is likewise deleted.
This example creates an observer, then disconnects from it, leaving it available for possible reuse.
const targetNode = document.querySelector("#someElement");
const observerOptions = {
childList: true,
attributes: true
}
const observer = new MutationObserver(callback);
observer.observe(targetNode, observerOptions);
/* some time later... */
observer.disconnect();
| 规范 | 状态 | 注释 |
|---|---|---|
|
DOM
The definition of 'MutationObserver.disconnect()' in that specification. |
实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
disconnect
|
Chrome 18 | Edge 12 | Firefox 14 | IE 11 | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 | Firefox Android 14 | Opera Android 14 | Safari iOS 6 | Samsung Internet Android 1.0 |
完整支持