首页 > 开发 > HTML > 正文

添加和删除HTML节点的简单示例

2020-06-14 22:45:14
字体:
来源:转载
供稿:网友

添加和删除HTML节点的简单示例

<input type="button" onclick="appendnode()" value="添加节点">
<input type="button" onclick="removenode()" value="删除节点">
<div id="result"></div>
<script>
i=0
function appendnode() {
o=document.createElement("DIV");
o.innerHTML="test" i
document.getElementById('result').appendChild(o);
i
}

function removenode(){
var x = document.getElementById('result');
x.removeChild(x.lastChild) //从最后个节点删除
}
</script>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表