用li模拟select实现下拉框
2016-01-22 15:05
357 查看
<!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> <title></title> <style> body {padding:10px;} * {margin:0; padding:0; font-size:12px;} ul,li { list-style-type:none; } .Select_box { width:150px; border:1px solid #ccc; padding-right:20px; padding-left:10px; position:relative; } #fisrt { cursor:pointer; display:block; line-height:25px; width:100%; height:25px; text-align:center; background:url('ico-arrow.png') no-repeat 100% 50%; } .Select_box ul li { cursor:pointer; } .son_ul { width:179px; position:absolute; left:0; top:25px; border:1px dashed #ccc; background:url(bg.png) no-repeat 0 0; z-index:100; } .son_ul li { display:block; line-height:25px; padding-left:0px; width:179px; z-index:100; background:url('icon.png') no-repeat 0% 60%; } .son_ul li:hover { background:red url('icon.png') no-repeat 0% 60%; } .son_ul span { cursor:pointer; padding-left:40px; } </style> <script src="jquery-1.4.2.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { $('.son_ul').hide(); //初始ul隐藏 $('.Select_box span').click(function () { //鼠标移动函数 $(this).parent().find('ul.son_ul').slideDown(); //找到ul.son_ul显示 //$(this).parent().find('li').hover(function () { $(this).addClass('hover') }, function () { $(this).removeClass('hover') }); //li的hover效果 $(this).parent().hover(function () { }, function () { $(this).parent().find("ul.son_ul").slideUp(); } ); }, function () { } ); $('ul.son_ul li').click(function () { $(this).parents('li').find('#fisrt').html($(this).html()); $(this).parents('li').find('ul').slideUp(); }); } ); </script> </head> <body> <form id="form1" runat="server"> <ul id="main_box"> <li class="Select_box"> <span id="fisrt"> 请选择...</span> <ul class="son_ul"> <li><span>选项一</span></li> <li><span>选项二</span></li> <li><span>选项三</span></li> <li><span>选项四</span></li> <li><span>选项五</span></li> </ul> </li> </ul> </form> </body> </html>
相关文章推荐
- C#基础
- 微信ANDROID客户端-会话速度提升70%的背后
- windows下的dig 命令和nslookup的用法及详例
- Laravel框架 mysql 数据库 —— 基本使用
- js获取单选button的值
- 关于Android Studio里的Gradle,你所需要知道的都在这里了
- 20160122--集合List
- Fiddler如何抓取手机APP数据包
- 一个实例说明java中的list,set,map三者区别
- SpringMVC之表单提交===③===多文件上传表单 http://h-king.iteye.com/blog/2269217
- 再你自己的APP中判断是否安装了别的APP,如没有,打开AppStore下载
- android 代码设置背景颜色
- 机器学习——深度学习(Deep Learning)
- 安卓手机的问题出在哪 -- 用户体验
- Tunnel Warfare
- python学习之--取模运算
- 【AppCan开发者故事】bodhi:小鲜肉的移动开发修炼手册
- react-native布局
- MPAndroidChart开源图表库
- FFMPEG研究: Android调试FFMPEG程序