码迷,mamicode.com
首页 > 其他好文 > 详细

div做下拉列表

时间:2017-06-20 00:14:14      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:cal   标题   oct   onclick   auto   type   round   add   meta   

<!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;}
#sel{ width:280px; height:40px; border:1px solid #C0F;
margin-top:100px; line-height:40px; vertical-align:middle; padding-left:20px;}
#list{ width:300px; height:200px; border-left:1px solid#c0f; border-right:1px solid#c0f;
}
.item{ width:280px; height:39px; border-bottom:1px solid#c0f; line-height:40px; vertical-align:middle; padding-left:20px;}
</style>
</head>

<body>

<div id="sel"></div>
<div id="list" style="display:none">
<div class="item" onmouseover="xz(this)" onclick="xuanzhong(this)">北京</div>
<div class="item" onmouseover="xz(this)" onclick="xuanzhong(this)">上海</div>
<div class="item" onmouseover="xz(this)" onclick="xuanzhong(this)">南京</div>
<div class="item" onmouseover="xz(this)" onclick="xuanzhong(this)">重庆</div>
<div class="item" onmouseover="xz(this)" onclick="xuanzhong(this)">深圳</div>
</div>

<!--<select>
<option>11</option>
<option>22</option>
<option>33</option>
</select>-->

</body>
<script type="text/javascript">

function xz(a){
//所有的还原
var sy =document.getElementsByClassName("item");
for(var i=0;i<sy.length;i++){
sy[i].style.backgroundColor="white";
sy[i].style.color = "black";
}
//当前的选中
a.style.backgroundColor="blue";
a.style.color = "white";
}

var sel = document.getElementById("sel");
sel.onclick = function(){

var c = document.getElementById("list");
if(c.style.display=="none"){
c.style.display="block";
}else{
c.style.display="none";
}
}

function xuanzhong(a){
//隐藏
document.getElementById("list").style.display="none";
//取值
document.getElementById("sel").innerText = a.innerText;
}

</script>
</html>

div做下拉列表

标签:cal   标题   oct   onclick   auto   type   round   add   meta   

原文地址:http://www.cnblogs.com/dongtian1992/p/7051082.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!