js动态添加div
2014-10-04 01:11
253 查看
http://blog.csdn.net/cike121272604/article/details/5809114
<html>
<body>
<div id="a">
<div id="a1">1</div>
<div id="a2">2</div>
</div>
<a href="javascript:addDiv();">test</a>
</body>
<script type="text/javascript">
function addDiv(){
var newNode=document.createElement("div");
newNode.setAttribute("id","a3");
var txtNode=document.createTextNode("3");
newNode.appendChild(txtNode);
document.getElementById("a").insertBefore(newNode,document.getElementById("a2"));
alert(document.getElementById("a").innerHTML)
}
</script>
</html>
<html>
<body>
<div id="a">
<div id="a1">1</div>
<div id="a2">2</div>
</div>
<a href="javascript:addDiv();">test</a>
</body>
<script type="text/javascript">
function addDiv(){
var newNode=document.createElement("div");
newNode.setAttribute("id","a3");
var txtNode=document.createTextNode("3");
newNode.appendChild(txtNode);
document.getElementById("a").insertBefore(newNode,document.getElementById("a2"));
alert(document.getElementById("a").innerHTML)
}
</script>
</html>
相关文章推荐
- js 向 div 动态 添加 内容 table
- JS实现动态添加和删除DIV
- 文字添加响应事件,js动态加载CSS, js弹出DIV
- JS动态添加的div点击跳转到另一页面实现代码
- [zz]js动态div添加
- JS动态添加div、li、img等元素及设置属性(实例)
- 动态添加div及对应的js、css文件
- js动态添加的DIV中的onclick事件简单实例
- js动态添加div
- JS动态添加div,然后在div中添加元素
- js动态添加div
- js 动态创建div并向其中添加元素
- js动态添加div(二)
- js动态添加Div
- js 动态生成div 并添加class id
- js 动态添加元素(div、li、img等)及设置属性
- js动态添加div 用于java后台的form表单的提交
- js动态添加的div点击跳转到另一页面
- js动态添加的DIV中的onclick事件简单实例
- js 动态添加元素(div、li、img等)及设置属性的方法