请问为什么另一种写法不可以?
举例中,代码为:
<script type="text/javascript">
function replaceMessage(){
var newnode=document.createElement("p");
var newnodeText=document.createTextNode("JavaScript");
newnode.appendChild(newnodeText);
var oldNode=document.getElementById("oldnode");
oldNode.parentNode.replaceChild(newnode,oldNode);
}
</script>
<h1 id="oldnode">Java</h1>
<a href="javascript:replaceMessage()">"Java"替换"JavaScript"</a>
为什么不可以写成:
<script type="text/javascript">
function replaceMessage(){
var newnode=document.createElement("p");
newnode.appendChild(newnodeText);
newnodeText.innerHTML="JavaScript";
var oldNode=document.getElementById("oldnode");
oldNode.parentNode.replaceChild(newnode,oldNode);
}
</script>
<h1 id="oldnode">Java</h1>
<a href="javascript:replaceMessage()">"Java"替换"JavaScript"</a>