javascript 模拟select下拉列表效果

发布时间:2021-01-02编辑:脚本学堂
本文介绍了js模拟select下拉列表特效的实例代码,有需要的朋友参考下。

例子,javascript实现select下拉列表特效。
 

复制代码 代码示例:
<!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=gb2312" />
<title>javascript 模拟select下拉列表特效 by jb200.com</title>
<style type="text/css">
<!--
*{margin:0px;padding:0px;border:0px;}
ul ,li {margin: 0px;padding: 0px;list-style: none;}
.xmkc {height: 28px;width: 240px;position: relative;padding: 5px;border: 1px solid #CCCCCC;}
.xmkc .classlist {left: 5px;position: absolute;background-color: #F5FBFF;width: 156px;border: 1px solid #C9E4F4;top: 28px;font-size: 12px;line-height: 22px;padding-top: 5px;}
.xmkc .classlist li {display: inline;}
.xmkc .classlist .lis a {text-decoration: none;background-image: url(/images/i2.gif);background-repeat: no-repeat;background-position: 5px 7px;height: 22px;width: 151px;float: left;padding-left: 15px;}
.xmkc .classlist .close {text-decoration: none;height: 22px;width: 156px;float: left;background-color: #E7F2FA;text-align: right;border: 0px 0 0;padding-right: 10px;}
.xmkc .classlist .lis a:hover {color: #FFFFFF;background-color: #0E9CC8;}
.xmkc .classlist .lis a:active {color: #FFFFFF;background-color: #0D96C0;}
.wena {font-size: 12px;color: #FF6600;background-color: #FFFFFF;border-top-width: 1px;border-right-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-top-style: solid;border-right-style: solid;border-bottom-style: solid;border-left-style: solid;border-top-color: #096A89;border-right-color: #D3ECFF;border-bottom-color: #D3ECFF;border-left-color: #096A89;padding-right: 3px;padding-left: 3px;width: 160px;line-height: 20px;height: 18px;background-image: url(/images/nofollow.gif);background-repeat: no-repeat;background-position: 150px 5px;}
body {margin-left: 100px;margin-top: 50px;}
a:link {color: #333333;text-decoration: none;}
a:visited {text-decoration: none;color: #333333;}
a:hover {text-decoration: underline;color: #333333;}
a:active {text-decoration: none;color: #333333;}
-->
</style>
</head>
<script type="text/javascript">
function gets_id(objName){
if(document.getElementById){
return eval('document.getElementById("' + objName + '")');
}else if(document.layers){
return eval("document.layers['" + objName +"']");
}else{
return eval('document.all.' + objName);
}
}
//打开DIV层
function disp_cc()
{
if(gets_id('hh').style.display=='none')
{
gets_id('hh').style.display='';
}
else
{
gets_id('hh').style.display='none';
}
}
//赋值
function gets_value(str)
{
gets_id('class').value=str;
gets_id('hh').style.display='none';
}
</script>
<body>
<div class=xmkc>
<div><input name="class" type="text" class="wena" onClick="disp_cc();" value="请选择栏目"/>
<!--如果不要编辑,input增加readonly="readonly"--></div>
<div id="hh" style="display:none" class=classlist>
<ul> www.jb200.com
<!--可循环-->
<li class=lis><a href="#" onClick="gets_value('option标签1')">option值1</a></li>
<li class=lis><a href="#" onClick="gets_value('option标签2')">option值2</a></li>
<li class=lis><a href="#" onClick="gets_value('option标签3')">option值3</a></li>
<li class=lis><a href="#" onClick="gets_value('option标签4')">option值4</a></li>
</ul>
<span onclick="hh.style.display='none'" class=close><a href="#">关闭</a></span>
</div>
</div>
</body>
</html>