<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>
<div><b id="oldnode">JavaScript</b>是一个很常用的技术,为网页添加动态效果。</div>
<a href="javascript:replaceMessage()"> 将加粗改为斜体</a>
<script type="text/javascript">
function replaceMessage(){
var newnode=document.creatElement("i");
var oldnode=document.getElementById("oldnode");
newnode.innerHTML=oldnode.innerHTML;
odlnode.parentNode.replaceChild(newnode,oldnode);
}
</script>
</body>
</html>
为什么运行不出想要的结果
function replaceMessage(){ var newNode=document.createElement("i"); var newText=document.createTextNode("JavaScript"); newNode.appendChild(newText); var oldNode=document.getElementById("oldnode"); oldNode.parentNode.replaceChild(newNode,oldNode); }