小白教程
所有教程
关于
Search
172.70.131.190
172.70.131.190
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Met document createtextnode”的源代码
本页内容
上一节:
Met_document_createelement
下一节:
Prop_document_doctype
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:document.createTextNode()}}[[Category:dom obj document|13]] = HTML DOM createTextNode() 方法 = [[dom obj document|Document 对象]] 创建一个文本节点: <sample title="" desc="" lang="html" hererun="1"> var btn=document.createTextNode("Hello World"); </sample> 输出结果: <sample title="" desc="" lang="html" hererun="1"> Hello World </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> </head> <body> <p id="demo">单击按钮创建文本节点。</p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ var t=document.createTextNode("Hello World"); document.body.appendChild(t); }; </script> </body> </html> </run> HTML元素通常是由元素节点和文本节点组成。 创建一个标题 (H1), 你必须创建 "H1" 元素和文本节点: 创建一个标题: <sample title="" desc="" lang="html" hererun="1"> var h=document.createElement("H1") var t=document.createTextNode("Hello World"); h.appendChild(t); </sample> 输出结果: <sample title="" desc="" lang="html" hererun="1"> Hello World </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> </head> <body> <p id="demo">单击按钮创建一个标题</p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ var h=document.createElement("H1"); var t=document.createTextNode("Hello World"); h.appendChild(t); document.body.appendChild(h); }; </script> </body> </html> </run> == 定义和用法 == createTextNode() 可创建文本节点。 == 浏览器支持 == 所有主要浏览器都支持 createTextNode() 方法 == 语法 == <pre> document.createTextNode(text)</pre> == 参数 == {| class="table table-striped table-hover" ! 参数 ! 类型 ! 描述 |- | text | String | 必须。文本节点的文本。 |} == 返回值 == {| class="table table-striped table-hover" ! 类型 ! 描述 |- | 文本节点对象 | 创建文本节点 |} == 技术细节 == {| class="table table-striped table-hover" | DOM 版本 | Core Level 1 Document Object |} [[dom obj document|Document 对象]]
返回至“
Met document createtextnode
”。
上一节:
Met_document_createelement
下一节:
Prop_document_doctype