<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete - Combobox</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
<style>
.custom-combobox {
position: relative;
display: inline-block; }
.custom-combobox-toggle {
position: absolute;
top: 0;
bottom: 0;
margin-left: -1px;
padding: 0;
width:23px;
}
.custom-combobox-input {
margin: 0;
padding: 3px 0px;
}
</style>
<script>
(function( $ ) {
$.widget( "custom.combobox", {
_create: function() {
this.wrapper = $( "<span>" )
.addClass( "custom-combobox" )
.insertAfter( this.element ); this.element.hide();
this._createAutocomplete();
this._createShowAllButton();
}, _createAutocomplete: function() {
var selected = this.element.children( ":selected" ),
value = selected.val() ? selected.text() : ""; this.input = $( "<input>" )
.appendTo( this.wrapper )
.val( value )
.attr( "title", "" )
.addClass( "custom-combobox-input ui-widget-content ui-state-default ui-corner-left" )
.autocomplete({
delay: 0,
minLength: 0,
source: $.proxy( this, "_source" )
})
.tooltip({
tooltipClass: "ui-state-highlight"
}); this._on( this.input, {
autocompleteselect: function( event, ui ) {
ui.item.option.selected = true;
this._trigger( "select", event, {
item: ui.item.option
});
}, autocompletechange: "_removeIfInvalid"
});
}, _createShowAllButton: function() {
var input = this.input,
wasOpen = false; $( "<a>" )
.attr( "tabIndex", -1 )
.attr( "title", "Show All Items" )
.tooltip()
.appendTo( this.wrapper )
.button({
icons: {
primary: "ui-icon-triangle-1-s"
},
text: false
})
.removeClass( "ui-corner-all" )
.addClass( "custom-combobox-toggle ui-corner-right" )
.mousedown(function() {
wasOpen = input.autocomplete( "widget" ).is( ":visible" );
})
.click(function() {
input.focus(); // Close if already visible
if ( wasOpen ) {
return;
} // Pass empty string as value to search for, displaying all results
input.autocomplete( "search", "" );
});
}, _source: function( request, response ) {
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
response( this.element.children( "option" ).map(function() {
var text = $( this ).text();
if ( this.value && ( !request.term || matcher.test(text) ) )
return {
label: text,
value: text,
option: this
};
}) );
}, _removeIfInvalid: function( event, ui ) { // Selected an item, nothing to do
if ( ui.item ) {
return;
} // Search for a match (case-insensitive)
var value = this.input.val(),
valueLowerCase = value.toLowerCase(),
valid = false;
this.element.children( "option" ).each(function() {
if ( $( this ).text().toLowerCase() === valueLowerCase ) {
this.selected = valid = true;
return false;
}
}); // Found a match, nothing to do
if ( valid ) {
return;
} // Remove invalid value
this.input
.val( "" )
.attr( "title", value + " didn't match any item" )
.tooltip( "open" );
this.element.val( "" );
this._delay(function() {
this.input.tooltip( "close" ).attr( "title", "" );
}, 2500 );
this.input.autocomplete( "instance" ).term = "";
}, _destroy: function() {
this.wrapper.remove();
this.element.show();
}
});
})( jQuery ); $(function() {
$( "#sub_tea_id_select" ).combobox();
$( "#toggle" ).click(function() {
$( "#sub_tea_id_select" ).toggle();
});
});
</script>
</head>
<body>
<center>
<div >
<label>Your preferred programming language: </label>
<select id="sub_tea_id_select">
<option value="00001">00001 李建欣</option>
<option value="00002">00002 沃天宇</option>
<option value="00003">00003 刘旭东</option>
<option value="11001">11001 李未</option>
<option value="11002">11002 怀进鹏</option>
<option value="11003">11003 呂卫锋</option>
<option value="11061032">11061032 魏佳丽</option>
</select>
</div>
<button id="toggle">Show underlying select</button>
</center> </body>
</html>

可输入自动匹配Select——jquery ui autocomplete的更多相关文章

  1. jQuery UI Autocomplete是jQuery UI的自动完成组件

    支持的数据源 jQuery UI Autocomplete主要支持字符串Array.JSON两种数据格式. 普通的Array格式没有什么特殊的,如下: ? 1 ["cnblogs" ...

  2. jQuery UI Autocomplete是jQuery UI的自动完成组件(share)

    官网:http://jqueryui.com/autocomplete/ 以下分享自:http://www.cnblogs.com/yuzhongwusan/archive/2012/06/04/25 ...

  3. Jquery ui autocomplete简单api

    重要说明:与配置选项类似,Autocomplete插件的方法也不是直接调用,而且通过autocomplete()方法进行间接调用.例如: $("#title").autocompl ...

  4. jQuery UI AutoComplete的使用

    现场提出优化单,Table Mapping里关于获取数据源下所有表名的地方由于表数量过多选择不便,需添加搜索功能.原本的实现是一个Dialog ,现打算将其改为AutoComplete. 框架使用的是 ...

  5. jquery ui autocomplete 实现点击文本框,出现所有查询信息效果,与bootstrap结合使用修改样式

    直接看代码 <!doctype html> <html lang="en"> <head> <meta charset="utf ...

  6. jQuery ui autocomplete下拉列表样式失效解决,三种获取数据源方式,

    jQuery有很多很多的已经实现,很漂亮的插件,autocomplete就是其中之一.jQuery ui autocomplete主要支持字符串Array.JSON两种数据格式,jQuery ui b ...

  7. JQuery UI Autocomplete与jquery.autocomplete.js

    程序中要把一个select改成可以下拉搜索的,就想到了使用下autocomplete.js大概是这么个东西. 问了下同学,推荐我使用Jquery Ui autocomplete,下载下来开始调试使用, ...

  8. jQuery UI Autocomplete Combobox 配 ASP.NET DropDownList

    0.引言   1.起因                  一开始使用Autocomplete做了一个自动补全的文本框,如上图.后来因业务需要希望能在这个文本框的边上做个下拉列表按钮,一按就展开所有支持 ...

  9. jquery UI autocomplete当输入框焦点聚焦时自动弹出跟随下拉框

    $("#search").autocomplete({ minLength: 0, source: function(request,response){ // request对象 ...

随机推荐

  1. [资料]常用Windows CMD指令

    1. 查找80端口开放情况 netstat -aon|findstr “80″ 2. 用netstat查询端口占用程序的PID,显示列表的最后一列就是占用程序的PID,然后再利用tasklist找到这 ...

  2. windows 批处理把所有java源码导入一个txt文件中

    首先在src下搜*.java,把搜到的文件全拷出来放在allsrc目录下, 然后在allsrc目录下建个run.bat,键入以下内容for %%i in (*.java)  do type %%i&g ...

  3. 地图投影——高斯-克吕格投影、墨卡托投影和UTM投影

    地图投影(Map Projection) http://baike.baidu.com/view/94066.htm 概念: 地图投影是把地球表面的任意点,利用一定数学法则,转换到地图平面上的理论和方 ...

  4. 文件“D:\file.txt”正由另一进程使用,因此该进程无法访问该文件。

    关于如题的解决方案! 都是有一定编程基础的人,我就不讲其它的了. 1.在实例化一个FileStream后,用完它一定要关闭.先试试这一条: 2.第一条不起作用的话,用本条.在实例化FileStream ...

  5. C#创建Windows Service(Windows 服务)基础教程

    Windows Service这一块并不复杂,但是注意事项太多了,网上资料也很凌乱,偶尔自己写也会丢三落四的.所以本文也就产生了,本文不会写复杂的东西,完全以基础应用的需求来写,所以不会对Window ...

  6. [CareerCup] 5.8 Draw Horizonatal Line 画横线

    5.8 A monochrome screen is stored as a single array of bytes, allowing eight consecutive pixels to b ...

  7. [CareerCup] 11.6 Search a 2D Matrix 搜索一个二维矩阵

    11.6 Given an M x N matrix in which each row and each column is sorted in ascending order, write a m ...

  8. 信息安全系统设计基础实验五:简单嵌入式 WEB 服务器实验 (20135229,20135234)

    http://www.cnblogs.com/mqy123/p/5002683.html

  9. Java中的String、StringBuffer以及StringBuilder的用法和区别

    String String的构造方式有n种(据说n==11),常见的例举一二: String s1 = "hello world"; String s2 = new String( ...

  10. IT男的”幸福”生活"续1

    IT男的”幸福”生活"续1 我和LL开始下步追妹计划...... 知彼知已,方能把握机会.没想到孙子兵法太给力了,据LL了解,MM(她)是湖北人,找对象一般不会考虑外省的.高度165左右,相 ...