Document.createDocumentFragment()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
建立新的 DocumentFragment
.
語法
var fragment = document.createDocumentFragment();
fragment
是 DocumentFragment
的一個參考物件。
描述
舉例
這個例子中用清單來呈現主流瀏覽器。
HTML
html
<ul id="ul"></ul>
JavaScript
js
var element = document.getElementById("ul"); // assuming ul exists
var fragment = document.createDocumentFragment();
var browsers = ["Firefox", "Chrome", "Opera", "Safari", "Internet Explorer"];
browsers.forEach(function (browser) {
var li = document.createElement("li");
li.textContent = browser;
fragment.appendChild(li);
});
element.appendChild(fragment);
結果
在 jsfiddle 上看範例結果。
規格
Specification |
---|
DOM # ref-for-dom-document-createdocumentfragment① |
瀏覽器相容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
createDocumentFragment |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.