- 浏览: 219187 次
- 性别:
- 来自: 北京
文章分类
最新评论
jQuery ui 是一个UI的雏形, 一些UI都基于jQuery ui 开发,例如easy ui。
最近项目用jquery ui 做前台,需要用到 combobox组件, 如果用easy ui 需要引入很多其他的js比较麻烦, jquery ui Demo中 autocomplete 里面自带一个Combobox, 但一些功能不是我们想要的。
自己在上面增加了几个方法和事件。 并修改了对IE6支持的CSS 如下:
好处: 下拉框的样式随jquery ui 的样式改变而改变, 支持自动补全
不足: 方法需要自己扩展
————————————————————————————————————————
参数:
tip: "提示",
isReadonly: true, //默认下拉框值不可编辑, 如果设置为false, 那么下拉框支持自动补全
增加方法说明:
事件:
1.onChange: 当下拉框修改选中一条时候触发
方法:
主动设置下拉框内容
1.$( "#combobox" ).combobox('setSelect', 'option中value', 'option中text');
————————————————————————————————————————
测试:
Html: <select id="combobox"> ... </select> 依赖: jquery ui 为1.9.1 需要依赖jquery ui、 jquery <link rel="stylesheet" type="text/css" href="jquery/jqueryui/css/redmond/jquery-ui.custom.min.css" /> <link rel="stylesheet" type="text/css" href="jquery/jqueryui/combobox/jquery.combobox.css" /> <script src="jquery/jquery.min.js" type="text/javascript"></script> <script src="jquery/jqueryui/js/jquery-ui.custom.min.js" type="text/javascript"></script> <script src="jquery/jqueryui/combobox/jquery.combobox.js" type="text/javascript"></script> $( "#combobox" ).combobox({ tip: "鼠标划入下拉按钮时候会有提示!", onChange: function(option){ alert($(option).attr('value')); } });
(function( $ ) { $.widget( "ui.combobox", { version: "1.9.1", options: { tip: "", isReadonly: true, /** * This event fire after selected select. */ onChange: function(option) {} }, input: null, _create: function() { var that = this, select = this.element.hide(), selected = select.children( ":selected" ), value = selected.val() ? selected.text() : "", wrapper = this.wrapper = $( "<span>" ) .addClass( "ui-combobox" ) .insertAfter( select ); function removeIfInvalid(element) { var value = $( element ).val(), matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( value ) + "$", "i" ), valid = false; select.children( "option" ).each(function() { if ( $( this ).text().match( matcher ) ) { this.selected = valid = true; return false; } }); if ( !valid ) { // remove invalid value, as it didn't match anything $( element ) .val( "" ) .attr( "title", value + " 没有匹配结果!" ) .tooltip( "open" ); select.val( "" ); setTimeout(function() { input.tooltip( "close" ).attr( "title", "" ); }, 2500 ); input.data( "autocomplete" ).term = ""; return false; } } input = $( "<input>" ) .appendTo( wrapper ) .val( value ) .attr( "title", "" ) // .addClass( "ui-state-default ui-combobox-input" ) .addClass( "ui-combobox-input" ) .autocomplete({ delay: 0, minLength: 0, source: function( request, response ) { var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" ); response( select.children( "option" ).map(function() { var text = $( this ).text(); if ( this.value && ( !request.term || matcher.test(text) ) ) return { label: text.replace( new RegExp( "(?![^&;]+;)(?!<[^<>]*)(" + $.ui.autocomplete.escapeRegex(request.term) + ")(?![^<>]*>)(?![^&;]+;)", "gi" ), "<strong>$1</strong>" ), value: text, option: this }; }) ); }, select: function( event, ui ) { ui.item.option.selected = true; that._trigger( "selected", event, { item: ui.item.option }); that.options.onChange(ui.item.option); }, change: function( event, ui ) { if ( !ui.item ) return removeIfInvalid( this ); } }) .addClass( "ui-widget ui-widget-content ui-corner-left" ); input.data( "autocomplete" )._renderItem = function( ul, item ) { return $( "<li>" ) .data( "item.autocomplete", item ) .append( "<a>" + item.label + "</a>" ) .appendTo( ul ); }; $( "<a>" ) .attr( "tabIndex", -1 ) .attr( "title", this.options.tip ) .tooltip() .appendTo( wrapper ) .button({ icons: { primary: "ui-icon-triangle-1-s" }, text: false }) //移除 // .removeClass( "ui-button" ) .removeClass( "ui-corner-all" ) .addClass( "ui-corner-right ui-combobox-toggle" ) .click(function() { // close if already visible if ( input.autocomplete( "widget" ).is( ":visible" ) ) { input.autocomplete( "close" ); removeIfInvalid( input ); return; } // work around a bug (likely same cause as #5265) $( this ).blur(); // pass empty string as value to search for, displaying all results input.autocomplete( "search", "" ); input.focus(); }); input .tooltip({ position: { of: this.button }, tooltipClass: "ui-state-highlight" }); if (this.options.isReadonly) { input.attr('readonly', true); } }, destroy: function() { this.wrapper.remove(); this.element.show(); $.Widget.prototype.destroy.call( this ); }, /** * Set input value * @param value option's value * @param text option's text */ setSelect: function(value, text) { input.val(text); } }); })( jQuery );
CSS
.ui-combobox { position: relative; display: inline-block; padding-right: 20px; } .ui-combobox-toggle { position: absolute; top: 0; bottom: 0; margin-left: -1px; padding: 0 0 0 0; /* adjust styles for IE 6/7 */ *height: 16px; *top: 0.1em; PADDING-RIGHT: 0px; width: 20px; } .ui-combobox-input { margin: 0; padding: 0em; width: 120px; }
发表评论
-
web界面父子页面互相调用
2017-10-27 14:25 580父页面:parent.html <!DOCT ... -
多选下拉框的回显(Select)
2015-10-20 17:29 10364多选下拉框打印时候是已数组形式展现的,按这种思路: &l ... -
jqgrid 网址
2015-05-13 16:41 497http://www.trirand.com/blog/jqg ... -
JQuery EasyUI combobox动态添加option
2015-03-20 09:41 1704<input class="easyui-c ... -
easy datagrid 获得page信息
2015-02-03 11:07 583var grid = $('#datagrid'); va ... -
easy ui datagrid api
2015-01-29 12:58 637http://www.jeasyui.com/document ... -
扩展easy ui tree 层级(level)
2014-12-22 10:38 838$.extend($.fn.tree.methods, { ... -
jquery 下拉框按text 选中
2014-11-18 16:03 430jQuery("#separator option[ ... -
jqGrid增加滚动条
2014-10-28 10:15 1867滚动条: $(xxx).jqGrid({ ...... aut ... -
jQuery ui 多选下拉
2014-09-25 11:49 978下载及代码:http://www.erichynds.com/ ... -
jqGrid 行编辑(select事件)动态追加控件(操作)
2014-09-15 11:26 7353在某个控件后面, 追加一个控件, 在某个控件下面设置 ... -
jQuery validate 自定义样式、规则
2014-09-12 17:07 1427jquery validate 常用的找Api 就好, 但有一 ... -
jqGrid自动适应窗口大小
2014-09-01 17:41 768$(window).resize(function(){ ... -
jqGrid 编辑自定义控件
2014-08-15 16:12 2358jqGrid 支持在某一列上,自己写一个控件显示,并影响弹出编 ... -
Ztree 常用
2014-08-14 17:36 1075Ztree 支持中文API 实在太easy 了, 有了API ... -
针对Ztree的右键弹出菜单(jquery.popupSmallMenu.js)
2014-08-14 10:21 6416例子效果: 右键菜单方便好用的有很多,长用的为jque ... -
jquery ui Message 简单使用
2014-08-12 10:09 1217可以自己在前面加上一张图片 通过operation判断 用哪张 ... -
jQuery layout 插件属性
2014-07-30 16:08 1619相信很多人在用layout的时候都会找layout到底有多少属 ... -
jqGrid 两种列模型(TypeError: b is undefined)
2014-07-23 18:06 979jqGrid 的json支持两种列模型 1:如果用普通的js ... -
BS UI
2014-07-21 16:07 345http://www.bootcss.com/ 支持IE6 ...
相关推荐
jquery-combobox2Demo 网上都有的例子保存在这里方面下载
for jQuery.UI v1.82 博文链接:https://waiting.iteye.com/blog/714655
java jquery easyui combobox 级联demo(真正可用) 注释详细
jquery.combobox 组件 可输入的选择框
jquery-combobox完美版,修复默认选择,滚动后无法关闭等问题 感谢同事 肖一兵大神
NULL 博文链接:https://wister.iteye.com/blog/850850
JQUERY Combobox
jQuery UI超级组合框一个简单的jQuery UI小部件,其行为类似于选择下拉列表,允许免费用户输入。 现场演示和安装说明。执照麻省理工学院
转载的,jquery-combobox select 可输入控件,很不错的东西
第三方控件 WenComboBox - ComboBox扩展[项添加图片]+源码+事例+文档
对WPF的ComboBox进行了扩展,现在可以在下拉列表中嵌入DataGrid/ListView/ListBox等数据控件,实现了展开后列表的自动选择,自动滚屏,并完全支持数据的绑定操作
最近在IE10中开发jquery,关于jquery中combobox多选不能兼容的问题,进行一些总结。 当给combobox设置属性“multiple:true”时,IE10无法完成多选,其报错如下: 代码如下: function _7e8(_7e9,_7ea){ var _7eb=$....
NULL 博文链接:https://see-you-again.iteye.com/blog/2284598
jquery-simple-combobox, 一个jQuery组合框( selectbox ) 插件 jQuery简单组合插件插件一个 jQuery combobox插件你可以将它用于自动完成( 搜索等) 。用法你可以在 index.html 中找到引用,并在这里查看 fiddles,以...
为jquery编写的扩展,仿easyui,清晰简洁,适合初学者,包含扩展jquery.accordion.js、jquery.combobox.js、jquery.datagrid.js、jquery.datebox.js、jquery.dialog.js、jquery.form.js、jquery.layout.js、jquery....
修改jquery easyui combobox模糊过滤 代码如下:filter:function(q,row){ var opts=$(this).combobox(“options”); //return row[opts.textField].indexOf(q)==0;// return row[opts.textField].indexOf(q)>-1;//将...