1.程序
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Insert title here</title> 6 <script type="text/javascript"> 7 window.onload=function(){ 8 var cityNode = document.getElementById("city"); 9 var gameNode = document.getElementById("game"); 10 11 //展示city的内容 12 alert(cityNode.innerHTML); 13 14 //互换 #city 节点和 #game 节点中的内容. 15 var tempHTML = cityNode.innerHTML; 16 cityNode.innerHTML = gameNode.innerHTML; 17 gameNode.innerHTML = tempHTML; 18 } 19 </script> 20 </head> 21 <body> 22 <body> 23 <p>你喜欢哪个城市?</p> 24 <ul id="city"> 25 <li id="bj" name="BeiJing">北京</li> 26 <li>上海</li> 27 <li id="dj">东京</li> 28 <li id="se">首尔</li> 29 </ul><br><br> 30 31 <p>你喜欢哪款单机游戏?</p> 32 <ul id="game"> 33 <li id="rl">红警</li> 34 <li>实况</li> 35 <li>极品飞车</li> 36 <li>魔兽</li> 37 </ul><br><br> 38 </body> 39 </html>
2.运行结果
互换后的结果: