jQuery EasyUI 为Combo,Combobox添加清除值功能的实例

效果图:

图标

rush:js;"> (function($){

//初始化清除按钮
function initClear(target){
var jq = $(target);
var opts = jq.data('combo').options;
var combo = jq.data('combo').combo;
var arrow = combo.find('span.combo-arrow');

var clear = arrow.siblings("span.combo-clear");
if(clear.size()==0){
//创建清除按钮。
clear = $('<span class="combo-clear" style="height: 20px;">');

//清除按钮添加悬停效果
clear.unbind("mouseenter.combo mouseleave.combo").bind("mouseenter.combo mouseleave.combo",function(event){
var isEnter = event.type=="mouseenter";
clearisEnter ? 'addClass' : 'removeClass';
}
);
//清除按钮添加点击事件,清除当前选中值及隐藏选择面板。
clear.unbind("click.combo").bind("click.combo",function(){
jq.combo("setValue","").combo("setText","");
jq.combo('hidePanel');
});
arrow.before(clear);
};
var input = combo.find("input.combo-text");
input.outerWidth(input.outerWidth()-clear.outerWidth());

opts.initClear = true;//已进行清除按钮初始化。
}

//扩展easyui combo添加清除当前值。
var oldResize = $.fn.combo.methods.resize;
$.extend($.fn.combo.methods,{
initClear:function(jq){
return jq.each(function(){
initClear(this);
});
},resize:function(jq){
//调用认combo resize方法
var returnValue = oldResize.apply(this,arguments);
var opts = jq.data("combo").options;
if(opts.initClear){
jq.combo("initClear",jq);
}
return returnValue;
}
});
}(jQuery));

HTML代码

rush:xhtml;">

js代码

rush:js;"> $('#myselect').comboBox({ required : true,editable : false }).comboBox("initClear");

css样式

rush:js;"> .combo-clear { background-color: #E0ECFF; width: 18px; height: 20px; overflow: hidden; display: inline-block; vertical-align: top; cursor: pointer; opacity: 0.6; filter: alpha(opacity=60); background: url('images/combo_clear.png') no-repeat center center; } .combo-clear-hover { opacity: 1.0; filter: alpha(opacity=100); background-color: #eaf2ff; }

以上这篇jQuery EasyUI 为Combo,ComboBox添加清除值功能的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程之家。

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...