Range.extractContents()

翻译不完整。 请帮助我们翻译这篇文章!

Range.extractContents() 方法移动了Range 中的内容从文档树到DocumentFragment(文档片段对象)。

使用DOM事件添加的事件侦听器在提取期间不会保留。 HTML属性事件将按Node.cloneNode()方法的原样保留或复制。 HTML id属性也会被克隆,如果提取了部分选定的节点并将其附加到文档中,则可能导致无效的文档。

克隆了部分选定的节点,以包括使文档片段有效所需的父标记。

Syntax

documentFragment = range.extractContents();

Example

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

Specifications

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

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
extractContentsChrome 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

See also