qq_曹振_0
2017-09-06 23:20
<!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.createElement("i");
var oldNode=document.getElementSByTagName("b");
var oldHTML=oldnode[0].innerHTML;
oldNode[0].parentNode.replaceChild(newnode,oldNode);
newnode.innerHTML=oldHTML;
}
</script>
</body>
</html>
懂了,原来replace里面是对象,我更加深入理解了这概念
<!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.getElementsByTagName("b");
var newnode=document.createElement("i");
newnode.innerHTML=oldnode[0].innerHTML
oldnode[0].parentNode.replaceChild(newnode,oldnode[0]);
}
</script>
</body>
</html>
document.getElementsByTagName("b");而你的Elements的s大写了
JavaScript进阶篇
468195 学习 · 21891 问题
相似问题