求解
<!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");
newnode.appendChild(oldnode.innerHTML);
oldnode.parentNode.replaceChild(newnode,oldnode);
}
</script>
</body>
</html>
oldnode.innerHTMl所取的东西不是节点,你查查InnerHTML 取的是什么
我改成了如下代码以后,还是变不了斜体,只是由粗体变细了
<script type="text/javascript">
function replaceMessage(){
var oldnode=document.getElementById("oldnode");
var newnode=document.createElement("i");
var xx=document.createTextNode(oldnode.innerHTML);
oldnode.parentNode.replaceChild(newnode.appendChild(xx),oldnode);
}
</script>