<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <style type="text/css"> *{ margin:0px auto; padding:0px} #xiala{ 200px; height:40px; border:1px solid #999;text-align:center; line-height:40px; vertical-align:middle;} #xiala:hover{ cursor:pointer} .list{ 200px; height:40px; text-align:center; line-height:40px; vertical-align:middle; border:1px solid #999; border-top-0px; display:none} .list:hover{ cursor:pointer; background-color:#63C; color:white;} </style> </head> <body> <br /> <div style="500px; height:500px;"> <div id="xiala" onclick="showa()"></div> <div class="list" onclick="xuan(this)">山东</div> <div class="list" onclick="xuan(this)">北京</div> <div class="list" onclick="xuan(this)">上海</div> <div class="list" onclick="xuan(this)">深圳</div> <div class="list" onclick="xuan(this)">广州</div> </div> <script type="text/javascript"> function showa() { var list = document.getElementsByClassName("list"); for(var i=0; i<list.length;i++) { list[i].style.display = "block"; } } function xuan(a) { var nr = a.innerHTML; document.getElementById("xiala").innerHTML=nr; var list = document.getElementsByClassName("list"); for(var i=0; i<list.length;i++) { list[i].style.display = "none"; } } </script> </body> </html>
效果如图: