<!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 oldNode = document.getElementById("oldnode");
var newnode = document.createElement("i");
var newnodeText = doucument.createTextNode(oldNode.innerHTML);
newnode.appendChild(newnodeText);
oldNode.parentNode.replaceChild(newnode,oldNode);
}
</script>
</body>
</html>
var newnodeText = doucument.createTextNode(oldNode.innerHTML);单词拼错了,这个要细心
逻辑上没问题,应该是拼写错了,创建新节点,把旧节点的内容给新节点,然后替换。