<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <title>模拟select下拉菜单</title> <style type="text/css"> .mod_select{position:absolute;left:30%;top:100px;font-familY:Arial,"microsoft yahei",Helvetica, sans-serif;} .mod_select ul{margin:0;padding:0;} .mod_select ul li{list-style-type:none;float:left;margin-left:20px;height:24px;} .mod_select .select_label{color:#333;float:left;line-height:27px;padding-right:10px;font-size:14px;font-weight:700;} .mod_select .select_box{float:left;border:solid 1px #49ad6d;color:#444;position:relative;cursor:pointer;width:165px;background:url(../select_bg.jpg) repeat-x;font-size:12px;} .mod_select .selet_open{display:inline-block;border-left:solid 1px #49ad6d;color: #49ad6d;position:absolute;right:0;top:0;width:30px;height:27px;line-height: 27px;text-align: center;} .mod_select .select_txt{display:inline-block;padding-left:10px;width:75%;line-height:24px;height:24px;cursor:text;overflow:hidden;white-space: nowrap;text-overflow:ellipsis;} .mod_select .option{width:165px;;border:solid 1px #49ad6d;position:absolute;top:24px;left:-1px;z-index:2;overflow:hidden;display:none;} .mod_select .option a{display:block;height:26px;line-height:26px;text-align:left;padding:0 10px;width:100%;background:#fff;} .mod_select .option a:hover{background:#ddd;} .mod_select a.all{font-weight: 600;padding-left: 2px;background: #eee;color: #aaa;} .mod_select a.manufacturer{font-weight: 600;padding-left: 2px;background: #f2f2f2;color: #555;} </style> <script src="http://apps.bdimg.com/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function(){ $(".select_box").click(function(event){ event.stopPropagation(); $(this).find(".option").toggle(); $(this).parent().siblings().find(".option").hide(); }); $(document).click(function(event){ var eo=$(event.target); if($(".select_box").is(":visible") && eo.attr("class")!="option" && !eo.parent(".option").length) $('.option').hide(); }); /*赋值给文本框*/ $(".option a").click(function(){ var value=$(this).text(); $(this).parent().siblings(".select_txt").text(value); $("#select_value").val(value) }) }) </script> </head> <body> <div class="mod_select"> <ul> <li> <span class="select_label">省份:</span> <div class="select_box"> <span class="select_txt"></span><a class="selet_open"><b>▼</b></a> <div class="option"> <a class="all">选择全部</a> <a class="manufacturer">厂商所有</a> <a>2</a> <a>3</a> <a class="manufacturer">1</a> <a>2</a> <a>3</a> </div> </div> <br clear="all" /> </li> <li> <span class="select_label">城市:</span> <div class="select_box"> <span class="select_txt"></span><a class="selet_open">▼</a> <div class="option"> <a>1</a> <a>2</a> <a>3</a> </div> </div> </li> </ul> <input type="hidden" id="select_value" /> </div> </body> </html> 提示:你可以先修改部分代码再运行。 http://www.dayday28.com/mod_select 转载请注明:有爱前端 » 兼容性很好的div模拟select下拉菜单 喜欢 (0)or分享 (0)