效果圖:
圖標(biāo)
(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){
//創(chuàng)建清除按鈕。
clear = $('');
//清除按鈕添加懸停效果。
clear.unbind("mouseenter.combo mouseleave.combo").bind("mouseenter.combo mouseleave.combo",
function(event){
var isEnter = event.type=="mouseenter";
clear[isEnter ? 'addClass' : 'removeClass']("combo-clear-hover");
}
);
//清除按鈕添加點(diǎn)擊事件,清除當(dāng)前選中值及隱藏選擇面板。
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;//已進(jìn)行清除按鈕初始化。
}
//擴(kuò)展easyui combo添加清除當(dāng)前值。
var oldResize = $.fn.combo.methods.resize;
$.extend($.fn.combo.methods,{
initClear:function(jq){
return jq.each(function(){
initClear(this);
});
},
resize:function(jq){
//調(diào)用默認(rèn)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代碼
成都 傳智播客 姚欣 小星星
js代碼
$('#myselect').combobox({
required : true,
editable : false
}).combobox("initClear");
css樣式
.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;