转发请注明出处,虽然转发几率不大。。。

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,位置,数据,是否可输入及输入提示效果都可作为参数直接传入的更多相关文章

  1. 联合县城市,采用ajax,而使用ul模拟select下拉

    接待处代码 js //采用jquery展示鼠标放到省ul下拉显示 $("#province").hover(function(){                          ...

  2. ul+js模拟select+改进

    html: <div class="select_box"> <input type="text" value="还款方式" ...

  3. ul -- li 模拟select下拉框

    在写项目中 用到下拉框,一般用 <select name="" id=""> <option value=</option> &l ...

  4. c# JD快速搜索工具,2015分析JD搜索报文,模拟请求搜索数据,快速定位宝贝排行位置。

    分析JD搜索报文 搜索关键字 女装 第二页,分2次加载. rt=1&stop=1&click=&psort=&page=3http://search.jd.com/Se ...

  5. 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 ...

  6. div 模拟<select>事件

    IE7 下,不能够自定义<select>/<option>的样式,所以为了方便起见,用div可以进行模拟 <!doctype html> <html> ...

  7. 模拟提交API数据Pyqt版

    其实这个模拟提交数据之前已经写过篇: Python requests模拟登录 因为现在在做的项目中需要一个debug请求调试API,用PHP的CURL写了一个,又因Pyqt更能直观灵活的显示请求的参数 ...

  8. jQuery插件:模拟select下拉菜单

    没搞那么复杂,工作中,基本够用.. <!doctype html> <html> <head> <meta charset="utf-8" ...

  9. 模拟select,隐藏下拉列表的几种实现

    前言 平时开发过程中,出于各种原因模拟原生slect的要求并不算少见. 在实现的过程中,点击其他区域隐藏下拉列表,又是一个必备的功能, 最近在一次开发的过程中引发了点思考,做下总结. 现象 实际中的实 ...

随机推荐

  1. 448. Find All Numbers Disappeared in an Array 寻找有界数组[1,n]中的缺失数

    [抄题]: Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice ...

  2. 一个虚拟机网络的XML描述

    <?xml version="1.0" encoding="utf-8"?> <VNET> <ID>1</ID> ...

  3. HighCharts SVN IReport进行PDF报表设计--模板

    BOS物流项目笔记第十五天 HIghcharts是很强大的图表绘制插件,它是基于纯js绘制的.当然地,对于图表也会有很多操作了.下面就我工作时遇到的一些比较常见的highcharts的操作进行小结,不 ...

  4. Win10 DHCP和Static IP 切换

    创建两个.bat文件,分别命名为static.bat和dhcp.bat static.bat文件写入 netsh interface ip set address "Wi-Fi" ...

  5. 利用 Aspose.Words 组件,在不依赖与 Office 组件的情况下把 Word 文件转换成 HTML 代码。

    首先利用 Nuget 获取 Aspose.Words.dll public ActionResult AsposeWordsDemo() { string srcFileName = Server.M ...

  6. .net Reflection(反射)- 一

    Reflection 反射需要引用 using System.Reflection; 命名空间.  通过 Assembly 类的 Load( ); 加载指定的 程序集 Assembly 是不能被实例化 ...

  7. Js 正则获取Html元素

    var html = $("#summaryTemplate").html(); var imageMath = /<img [^<,>]*(?=target-t ...

  8. Android 学习笔记 文本文件的读写操作

    activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&qu ...

  9. 阿里 RPC 框架 DUBBO 初体验

    最近研究了一下阿里开源的分布式RPC框架dubbo,楼主写了一个 demo,体验了一下dubbo的功能. 快速开始 实际上,dubbo的官方文档已经提供了如何使用这个RPC框架example代码,基于 ...

  10. 模拟Springboot二:内置tomcat

    既然要将tomcat内置到项目中,并且能够成功的启动项目就要知道 tomcat  做了哪些事情 ,那么就必须先搞明白 一个 普通的web项目是如何被我们本地配置的tomcat启动并运行的 (1). 先 ...