添加和刪除HTML節(jié)點(diǎn)的簡單示例
<input type="button" onclick="appendnode()" value="添加節(jié)點(diǎn)">
<input type="button" onclick="removenode()" value="刪除節(jié)點(diǎn)">
<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) //從最后個(gè)節(jié)點(diǎn)刪除
}
</script>