//父亲元素.replaceChild(新,旧)
1 <ul id="city">
2 <li id="bj">北京</li>
3 <li id="sh">上海</li>
4 <li id="gz">广州</li>
5 </ul>
6
7 <ul id="color">
8 <li id="red">红色</li>
9 <li id="green">绿色</li>
10 <li id="blue">蓝色</li>
11 </ul>
12 <script type="text/javascript">
13 var gzLiElement=document.getElementById("gz");
14 gzLiElement.onclick=function(){
15 var colorElement=document.getElementById("color");
16 //父亲元素.replaceChild(新,旧)
17 document.getElementById("city").replaceChild(colorElement,this);
18 alert("xx");
19 }
js replaceChild
时间: 2024-11-10 07:55:51