<body> <div><b id="oldnode">JavaScript</b>是一个很常用的技术,为网页添加动态效果。</div> <a href="javascript:replaceMessage()" onClick="replaceMessage()"> 将加粗改为斜体</a> <script type="text/javascript"> function replaceMessage(){ var ohtml = document.getElementById("oldnode").innerHTML; var oldNode =document.getElementById("oldnode"); var newNode = document.createElement("i"); newNode.innerHTML = ohtml; oldNode.parentNode.replaceChild("newNode,oldNode") } </script> </body>
replaceChild();里面的内容不用加引号