37. Element appendChild() 方法
来源:互联网 发布:写安卓软件 编辑:程序博客网 时间:2024/05/21 06:01
实例
在列表中添加项目:document.getElementById("myList").appendChild(newListItem);添加之前:CoffeeTea添加之后:CoffeeTeaWater
<body><ul id="myList"><li>Coffee</li><li>Tea</li></ul><p id="demo">请点击按钮向列表中添加项目。</p><button onclick="myFunction()">亲自试一试</button><script>function myFunction(){var node=document.createElement("li");var textnode=document.createTextNode("Water");node.appendChild(textnode);document.getElementById("myList").appendChild(node);}</script></body>
定义和用法
appendChild() 方法向节点添加最后一个子节点。
提示:如果您需要创建包含文本的新段落,请记得添加到段落的文本的文本节点,然后向文档添加该段落。
您也可以使用 appendChild() 方法从一个元素向另一个元素中移动元素。
<ul id="myList1"><li>Coffee</li><li>Tea</li></ul><ul id="myList2"><li>Water</li><li>Milk</li></ul><p id="demo">请点击按钮把项目从一个列表移动到另一个列表中。</p><button onclick="myFunction()">亲自试一试</button><script>function myFunction(){var node=document.getElementById("myList2").lastChild;document.getElementById("myList1").appendChild(node);}</script>
0 0
- 37. Element appendChild() 方法
- JS方法: appendChild()
- HTML DOM appendChild()方法
- js appendChild方法应用
- js中appendChild()方法
- insertBefore()方法 和 appendChild() 方法
- appendChild,setAttribute方法的兼容性
- appendChild()
- JS插入节点的方法appendChild、insertBefore
- Javascript中的appendChild() 方法的理解
- createElement、appendChild、removeChild等方法的应用
- Ext submit时报错 Failed to execute 'appendChild' on 'Node': The new child element is null.
- IE中table标签不支持javascript的appendChild方法
- js节点内部插入元素的方法appendChild() insertBefore()
- JS(JavaScript)插入节点的方法appendChild与insertBefore
- JS(JavaScript)插入节点的方法appendChild与insertBefore
- 通过createElement(),createTextNode),appendChild()方法来显示文字
- appendChild()和insertBefore()方法插入元素的区别
- yii2 多数据库操作
- bootstrap v3学习笔记之JavaScript插件
- "ALT+/" eclipse快捷键失效问题
- 实现IEnumerator 已支持foreach
- Android Studio实战技巧
- 37. Element appendChild() 方法
- android 5.0新特性学习总结之下拉刷新(一)
- ASP.Net在web.config中设置上传文件的大小方法 (转)
- 诚信
- Spring @Required注释
- IOS TableView详解(二)
- 学PHP那点事?
- php中abstract和interface的区别
- C#中泛型的详细介绍