1.程序
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
window.onload=function(){
var cityNode = document.getElementById("city");
var gameNode = document.getElementById("game"); //展示city的内容
alert(cityNode.innerHTML); //互换 #city 节点和 #game 节点中的内容.
var tempHTML = cityNode.innerHTML;
cityNode.innerHTML = gameNode.innerHTML;
gameNode.innerHTML = tempHTML;
}
</script>
</head>
<body>
<body>
<p>你喜欢哪个城市?</p>
<ul id="city">
<li id="bj" name="BeiJing">北京</li>
<li>上海</li>
<li id="dj">东京</li>
<li id="se">首尔</li>
</ul><br><br> <p>你喜欢哪款单机游戏?</p>
<ul id="game">
<li id="rl">红警</li>
<li>实况</li>
<li>*飞车</li>
<li>魔兽</li>
</ul><br><br>
</body>
</html>
2.运行结果
互换后的结果: