Range.createContextualFragment()
方法返回
DocumentFragment
by invoking the HTML fragment parsing algorithm or the XML fragment parsing algorithm with the start of the range (the
parent
of the selected node) as the context node. 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
Text that contains text and tags to be converted to a document fragment.
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);
| 规范 | 状态 | 注释 |
|---|---|---|
|
DOM 剖析和序列化
The definition of 'Range.createContextualFragment()' in that specification. |
工作草案 | 最初的规范。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
createContextualFragment
|
Chrome Yes | Edge 12 | Firefox Yes | IE 11 | Opera 15 | Safari 9 | WebView Android Yes | Chrome Android Yes | Firefox Android Yes | Opera Android 14 | Safari iOS Yes | Samsung Internet Android Yes |
完整支持
实验。期望将来行为有所改变。
范围
cloneContents()
cloneRange()
collapse()
compareBoundaryPoints()
compareNode()
comparePoint()
createContextualFragment()
deleteContents()
detach()
extractContents()
getBoundingClientRect()
getClientRects()
insertNode()
intersectsNode()
isPointInRange()
selectNode()
selectNodeContents()
setEnd()
setEndAfter()
setEndBefore()
setStart()
setStartAfter()
setStartBefore()
surroundContents()
toString()
AbortController
AbortSignal
AbstractRange
Attr
ByteString
CDATASection
CSSPrimitiveValue
CSSValue
CSSValueList
CharacterData
ChildNode
注释
CustomEvent
DOMConfiguration
DOMError
DOMErrorHandler
DOMException
DOMImplementation
DOMImplementationList
DOMImplementationRegistry
DOMImplementationSource
DOMLocator
DOMObject
DOMParser
DOMPoint
DOMPointInit
DOMPointReadOnly
DOMRect
DOMString
DOMTimeStamp
DOMTokenList
DOMUserData
Document
DocumentFragment
DocumentType
元素
ElementTraversal
Entity
EntityReference
事件
EventTarget
HTMLCollection
MutationObserver
节点
NodeFilter
NodeIterator
NodeList
NonDocumentTypeChildNode
ProcessingInstruction
PromiseResolver
StaticRange
文本
TextDecoder
TextEncoder
TimeRanges
TreeWalker
TypeInfo
USVString
UserDataHandler
XMLDocument