Range.cloneContents()

翻译正在进行中。

Range.cloneContents() 返回一个 DocumentFragment,它是 Range 中所有的 Node 对象的副本。

使用" DOM 事件"添加的“事件侦听器”在克隆过程中不会被复制。 HTML属性事件与“DOM Core cloneNode”方法一样被复制。“HTML id属性”也将被克隆,这可能导致通过克隆导致无效的文档。

Partially selected nodes include the parent tags necessary to make the document fragment valid.

语法

documentFragment = range.cloneContents();

例子

range = document.createRange();
range.selectNode(document.getElementsByTagName("div").item(0));
documentFragment = range.cloneContents();
document.body.appendChild(documentFragment);

 规范

Specification Status Comment
DOM
Range.cloneContents()
Living Standard No change.
Document Object Model (DOM) Level 2 Traversal and Range Specification
Range.cloneContents()
Obsolete Initial specification.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
cloneContentsChrome Full support YesEdge Full support 12Firefox Full support 4IE Full support 9Opera Full support 9Safari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support

参考