MDN wants to talk to developers like you: https://qsurvey.mozilla.com/s3/8d22564490d8

Range.createContextualFragment()

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

Range.createContextualFragment() 该方法通过调用HTML片段解析算法或XML片段解析算法返回一个文档片段 DocumentFragment

The HTML fragment parsing algorithm is used if the range belongs to a Document whose HTMLness bit is set. In the HTML case, if the context node would be html, for historical reasons the fragment parsing algorithm is invoked with body as the context instead.

语法

documentFragment = range.createContextualFragment( tagString )

参数

tagString
被转换为文档片段( DocumentFragment )的字符串,包含文本及标记( text and tags )。

例子

var tagString = "<div>I am a div node</div>";
var range = document.createRange();
// make the parent of the first div in the document becomes the context node
range.selectNode(document.getElementsByTagName("div").item(0));
var documentFragment = range.createContextualFragment(tagString);
document.body.appendChild(documentFragment);

规范

Specification Status Comment
DOM Parsing and Serialization
Range.createContextualFragment()
Working Draft Initial specification.

浏览器兼容性

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) 11 15.0 9.1.2

 

Feature Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) 未实现 15.0 ?

See also

文档标签和贡献者

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