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.
实时标准

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
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

图例

完整支持

完整支持

元数据

  • 最后修改: