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

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. opennebula image单个实例响应数据格式

    { ", ", ", "TEMPLATE": { "DEV_PREFIX": "hd", " }, ...

  2. python 输入参数解包,模块导入,接收IO输入参数

    #coding=utf-8 from sys import argv script,first,second,third = argv print "the script is=" ...

  3. Docker学习笔记_Dockerfile基本知识

    Dockerfile由一行行命令语句组成,并支持以#开头的注释行. 1.编写一个Dockerfile文件 创建一个空的Docker工作目录,进入该目录,使用sudo vim Dockerfile指令新 ...

  4. webservice CXF 相关面试题

    Web Service的优点(1) 可以让异构的程序相互访问(跨平台)(2) 松耦合(3) 基于标准协议(通用语言,允许其他程序访问) 1:WEB SERVICE名词解释.JSWDL开发包的介绍.JA ...

  5. Unix基本系统数据类型和stat结构体

    Unix基本系统数据类型 历史上,某些UNIX变量已与某些C数据类型联系在一起,例如,历史上主.次设备号存放在一个1 6位的短整型中, 8位表示主设备号,另外8位表示次设备号.但是,很多较大的系统需要 ...

  6. mac安装nose,command not found:nosetests

    mac通过pip install nose失败,看了一下是权限的问题,重新用sudo pip install nose安装,安装成功. 但是执行nosetests时,提示command not fou ...

  7. C#中GUID的生成格式(Guid.ToString方法 )

    GUID 是微软对UUID这个标准的实现.UUID是由开放软件基金会(OSF)定义的.UUID还有其它各种实现,不止GUID一种 public string ToString(     string  ...

  8. HTTP Debugger Pro安装教程

    相关链接:HTTP Debugger Pro使用教程 安装步骤:   1.解压压缩包   2.双击运行安装文件   3.根据向导提示点击Next   4.选择接受协议,点击Next   5.选择高级模 ...

  9. MongoDB整理笔记のCRUD

    添加 下面我们来建立一个test 的集合并写入一些数据.建立两个对象j 和t , 并保存到集合中去.在例子里 “>” 来表示是 shell 输入提示符    > j = { name : ...

  10. .net在线HTML编辑器

    //在线网页编辑器, <script> var editor2 = new baidu.editor.ui.Editor({//实例化编辑器 initialContent: '', min ...