<div class="codetitle"> <span><a style="CURSOR: pointer" data="65923" class="copybut" id="copybut65923" onclick="doCopy('code65923')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code65923"> <br><title></title> <br><script type="text/javascript"> <BR>function createNode() { <BR>var pNode = document.createElement('p'); <BR>var tNode = document.createTextNode('烟花三月下杨州'); <BR>pNode.appendChild(tNode); <BR>document.body.appendChild(pNode); <BR>} <BR>function r() { <BR>var pNode = document.createElement('p'); <BR>var tNode = document.createTextNode('故人西辞黄鹤楼'); <BR>pNode.appendChild(tNode); <BR>//获取要替换的节点 <BR>var reNode = document.getElementsByTagName('p')[0]; <BR>//这种方法只适用于IE浏览器 <BR>//reNode.replaceNode(pNode, reNode); <BR>//适用于各种浏览器 <BR>reNode.parentNode.replaceChild(pNode, reNode); <BR>} <BR>function reNode() { <BR>var oldNode = document.getElementsByTagName('p')[0]; <BR>//oldNode.parentNode返回的是p节点的父节点,这里就是body <BR>//然后使用body节点的removeChild方法删除下的oldNode节点 <BR>oldNode.parentNode.removeChild(oldNode); <BR>} <BR></script> <br> <br> <br><input id="Button1" type="button" value="创建节点" onclick="createNode()"> <br><input id="Button2" type="button" value="替换节点" onclick="r()"> <br><input id="Button3" type="button" value="删除节点" onclick="reNode()"> <br> <br> </div>