Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Range.surroundContents

这篇翻译不完整。请帮忙从英语翻译这篇文章

Range.surroundContents()方法将Range对象的内容移动到一个新的节点, 并将这个新节点放到指定区域.

这个方法与newNode.appendChild(range.extractContents()); range.insertNode(newNode)很相近. 选定后, range拥有了节点标签.

也有例外情况, 如果选定的Range区域包含仅有一个节点标签的Text. 那标签将不会自动成对生成,操作将失败.

语法

range.surroundContents(newNode);

参数

newNode
一个放置区域内容的目标Node .

例子

var range = document.createRange();
var newNode = document.createElement("p");

range.selectNode(document.getElementsByTagName("div").item(0));
range.surroundContents(newNode);

规范

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

浏览器兼容

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) 1.0 (1.7 or earlier) [1] 9.0 9.0 (Yes)
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) 1.0 (1.0) [1] 9.0 9.0 (Yes)

[1] Before Firefox 1.5, a bug was preventing Range.surroundContents to work if the start and end of range were in same textnode (bug 135928).

相关链接

文档标签和贡献者

 此页面的贡献者: teoli, chyancheng
 最后编辑者: chyancheng,