小白教程
所有教程
关于
Search
172.70.126.139
172.70.126.139
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Met document createdocumentfragment”的源代码
本页内容
上一节:
Met_document_createcomment
下一节:
Met_document_createelement
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:document.createDocumentFragment()}}[[Category:dom obj document|11]] = HTML DOM createDocumentFragment() 方法 = [[dom obj document|Document 对象]] 创建一个 documentFragment 节点: <sample title="" desc="" lang="html" hererun="1"> var d=document.createDocumentFragment(); d.appendChild(document.getElementsByTagName("LI")[0]); d.childNodes[0].childNodes[0].nodeValue="Milk"; document.getElementsByTagName("UL")[0].appendChild(d); </sample> 输出结果: 修改前: <sample title="" desc="" lang="html" hererun="1"> Coffee Tea </sample> 修改后: <sample title="" desc="" lang="html" hererun="1"> Tea Milk </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> </head> <body> <ul><li>Coffee</li><li>Tea</li></ul> <p id="demo">单击按钮更改列表项,使用createDocumentFragment方法,然后在列表的最后一个孩子添加列表项。</p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ var d=document.createDocumentFragment(); d.appendChild(document.getElementsByTagName("LI")[0]); d.childNodes[0].childNodes[0].nodeValue="Milk"; document.getElementsByTagName("UL")[0].appendChild(d); }; </script> </body> </html> </run> == 定义和用法 == createdocumentfragment()方法创建了一虚拟的节点对象,节点对象包含所有属性和方法。 当你想提取文档的一部分,改变,增加,或删除某些内容及插入到文档末尾可以使用createDocumentFragment() 方法。 你也可以使用文档的文档对象来执行这些变化,但要防止文件结构被破坏,createDocumentFragment() 方法可以更安全改变文档的结构及节点。 == 浏览器支持 == 所有主要浏览器都支持 createDocumentFragment() 方法 == 语法 == <pre> document.createDocumentFragment()</pre> == 参数 == None. == 返回值 == {| class="table table-striped table-hover" ! 类型 ! 描述 |- | DocumentFragment 对象 | 创建文档片段对象 |} == 技术细节 == {| class="table table-striped table-hover" | DOM 版本 | Core Level 1 Document Object |} [[dom obj document|Document 对象]]
返回至“
Met document createdocumentfragment
”。
上一节:
Met_document_createcomment
下一节:
Met_document_createelement