用div做下拉列表

 1 <html xmlns="http://www.w3.org/1999/xhtml">
 2 <head>
 3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 4 <title>无标题文档</title>
 5 <style type="text/css">
 6 *{margin:0px auto;padding:0px;}
 7 #sel{width:280px;height:40px;border:1px solid #c0f;margin-top:100px;line-height:40px;vertical-align:middle;padding-left:20px;}
 8 #list{width:300px;height:200px;border-left:1px solid #c0f;border-right:1px solid #c0f;}
 9 .item{width:280px;height:39px;border-bottom:1px solid #c0f;line-height:40px;vertical-align:middle;padding-left:20px;}
10 </style>
11 </head>
12 
13 <body>
14 <div id="sel"></div>
15 <div id="list" style="display:none">
16     <div class="item" onmouseover="xz(this)" onclick="xuanzhong(this)">北京</div>
17     <div class="item" onmouseover="xz(this)" onclick="xuanzhong(this)">上海</div>
18     <div class="item" onmouseover="xz(this)" onclick="xuanzhong(this)">广州</div>
19     <div class="item" onmouseover="xz(this)" onclick="xuanzhong(this)">深圳</div>
20     <div class="item" onmouseover="xz(this)" onclick="xuanzhong(this)">重庆</div>
21     
22 </div>
23 </body>
24 <script type="text/javascript">
25 function xz(a){
26     var sy=document.getElementsByClassName("item");
27     for(var i=0;i<sy.length;i++){
28         sy[i].style.backgroundColor="white";
29         sy[i].style.color="black";
30     }
31     a.style.backgroundColor ="#ccc";
32     a.style.color="white";
33 }
34 
35 var sel=document.getElementById("sel");
36 sel.onclick =function(){
37     var c=document.getElementById("list");
38     if(c.style.display=="none"){
39         c.style.display="block";
40     }else{
41         c.style.display="none";
42     }
43 }
44 
45 function xuanzhong(a){
46     document.getElementById("list").style.display="none";
47     document.getElementById("sel").innerText =a.innerText;
48 }
49 </script>
50 </html>

转载于:https://www.cnblogs.com/zym0m/p/7050867.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值