ul模拟select,位置,数据,是否可输入及输入提示效果都可作为参数直接传入
转发请注明出处,虽然转发几率不大。。。
HTML
<span class="theContainer"></span>
CSS
body {padding:10px;}
* {margin:; padding:; font-size:12px;}
ul,li
{
list-style-type:none;
}
.theMockSelect{
width: 160px;
display: inline-block;
line-height: 20px;
position: relative;
}
.mockSelectBox{
display: block;
width: 180px;
overflow: hidden;
}
.liContainer{
width: 160px;
}
.liContainer li{
line-height:25px;
padding-left:5px;
display: block;
min-width: 170px;
}
.liContainer li:hover{
display:block;
background: #ccc;
}
.clickIcon{
position: absolute;
right: -10px;
top: 12px;
width:;
height:;
border-top: 8px solid #aaa;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 5px solid transparent;
}
.theInput{
display: block;
width: 90%;
height: 28px;
padding: 2px 8px;
font-size: 14px;
line-height: 1.42857143;
color: #555;
background-color: #fff;
background-image: none;
border: 1px solid #ccc;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
-webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
-o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
}
JS
$(document).ready(function () {
var theMockSelect = {
className:'theMockSelect', //一个ul的id,放模拟框
dataArray:['first','second','third','forth'],//数组数据
init:function(theContainer,data,flag){
this.className = theContainer?theContainer:this.className;
this.dataArray = data?data:this.dataArray;
var allTheLi='',theDataArray = this.dataArray;
$('.'+this.className).append('<ul class="theMockSelect"><li class="mockSelectBox"><input class="theInput" type="text" readonly="readonly"/><div class="clickIcon"></div><ul class="liContainer"></ul></li></ul>');
for(var i=0,l=theDataArray.length;i<l;i++){
allTheLi += '<li>'+theDataArray[i]+'</li>';
}
$('.liContainer').append(allTheLi);
//根据参数看是否想输入
$('.theInput').prop('readonly',flag);
this.allTheEvent();
},
allTheEvent:function(){
$('.liContainer').hide();
//点击下拉
$('.clickIcon').on('click',function () { //鼠标移动函数
var theUl = $(this).parent().find('.liContainer');
if(theUl.is(':hidden')) {
theUl.children().show();
theUl.slideDown(); //找到ul.son_ul显示
$(this).parent().find('li').hover(function () {
$(this).addClass('hover');
}, function () {
$(this).removeClass('hover')
});
}else {
theUl.slideUp();
}
});
//点击子元素
$('.liContainer li').on('click',function () {
$(this).parent().parent().find('input').val($(this).html());
$(this).parent().slideUp();
});
//输入事件
$('.theInput').on('keyup',function(){
var youInput = $(this).val();
$('.liContainer li').each(function(index,item){
if($(item).text().indexOf(youInput)>=0&&youInput!==''){
$(item).show();
$('.liContainer').slideDown();
}else {
$(item).hide();
}
});
});
}
};
theMockSelect.init('theContainer',['666','555','333','111'],false);
});
ul模拟select,位置,数据,是否可输入及输入提示效果都可作为参数直接传入的更多相关文章
- 联合县城市,采用ajax,而使用ul模拟select下拉
接待处代码 js //采用jquery展示鼠标放到省ul下拉显示 $("#province").hover(function(){ ...
- ul+js模拟select+改进
html: <div class="select_box"> <input type="text" value="还款方式" ...
- ul -- li 模拟select下拉框
在写项目中 用到下拉框,一般用 <select name="" id=""> <option value=</option> &l ...
- c# JD快速搜索工具,2015分析JD搜索报文,模拟请求搜索数据,快速定位宝贝排行位置。
分析JD搜索报文 搜索关键字 女装 第二页,分2次加载. rt=1&stop=1&click=&psort=&page=3http://search.jd.com/Se ...
- Bootstrap 3之美06-Page Header、Breadcrumbs、Dropdowns、Button Dropdowns、用Button和Dropdowns模拟Select、Input Groups、Thumbnails、Panels、Wells
本篇主要包括: ■ Page Header■ Breadcrumbs■ Button Groups■ Dropdowns■ Button Dropdowns■ 用Button和Dropdo ...
- div 模拟<select>事件
IE7 下,不能够自定义<select>/<option>的样式,所以为了方便起见,用div可以进行模拟 <!doctype html> <html> ...
- 模拟提交API数据Pyqt版
其实这个模拟提交数据之前已经写过篇: Python requests模拟登录 因为现在在做的项目中需要一个debug请求调试API,用PHP的CURL写了一个,又因Pyqt更能直观灵活的显示请求的参数 ...
- jQuery插件:模拟select下拉菜单
没搞那么复杂,工作中,基本够用.. <!doctype html> <html> <head> <meta charset="utf-8" ...
- 模拟select,隐藏下拉列表的几种实现
前言 平时开发过程中,出于各种原因模拟原生slect的要求并不算少见. 在实现的过程中,点击其他区域隐藏下拉列表,又是一个必备的功能, 最近在一次开发的过程中引发了点思考,做下总结. 现象 实际中的实 ...
随机推荐
- 599. Minimum Index Sum of Two Lists两个餐厅列表的索引和最小
[抄题]: Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of fa ...
- Java中迭代Map的方法
Map<String, String> mapServlet = new HashMap<String, String>(); System.out.println(" ...
- Razor内幕之解析
ASPX语法比较简单,所以ASPX解析器几乎完全是通过正则表达式来实现的.Razor解析器与ASPX解析器之间有很大不同,它实际上分为三个独立的组件: 1)理解基础HTML语法的标记解析器: 2)理解 ...
- javascript总结1:js常见页面消息输出方式 alert confirm console prompt document
.1 js常见的输出方法: 1-1 alert 警告框 alert("js语法总结"); 1-2 confirm 确认方法 confirm("js语法总结"); ...
- Chrome浏览器控件安装方法
说明:只需要安装up6.exe即可,up6.exe为插件集成安装包. 1.以管理员身份运行up6.exe.up6.exe中已经集成Chrome插件.
- XE中rectangle实现渐变
Fill -> Kind -> Gradient(选项) -> Gradient(Edit) 添加颜色即可
- aspx 与 ashx cs
1. aspx 与 ashx 我们知道 aspx :继承自 System.Web.UI.Page 然而Page:IHttpHandler public class Page : TemplateCon ...
- .net 基元类型,引用类型和值类型
基元类型(primitive type): 编译器直接支持的数据类型称为基元类型(primitive type). string 与 String: 由于C#中的string (一个关键字)直接映射到 ...
- 20145218张晓涵 PC平台逆向破解_advanced
---恢复内容开始--- 20145218张晓涵 PC平台逆向破解_advanced shellcode注入 基础知识 shellcode就是在利用溢出攻击溢出时要值入的代码,也就是溢出后去执行的代码 ...
- 记.gitignore的一次惊心动魄
git rm -r --cached . #清除缓存 git add . #重新trace file git commit -m "update .gitignore" #提交和 ...