选择下拉框,"不选"放第一位,添加一个初始化事件,写一下js语句。
var self = this;
self.options.name4Empty = "不选" ;//默认为不选 可以自定义修改
$('input',this.element).click(function(){
if(self.$view.css('display')=='none'){
self.onTriggerClick();
}
});
//全部选择放在第一位
this.addData2View = function(c){
var e = this.editComp.val();
var b = -1;
if (this.$view) {
this.emptyContent = $("<div/>");
//默认的空添加到第一个位置
this.initContent(this.emptyContent, this.options.name4Empty, 0);
this.$view.append(this.emptyContent);
var l = document.createDocumentFragment();
var g = this.options.data.getLength();
for (var d = g - c.length; d < g; d++) {
var k = d + c.length - g;
var h = $("<div/>");
l.appendChild(h[0]);
var f = c[k].getShowValue();
this.initContent(h, f, d+1);
if (b < 0 && f == e) {
b = k
}
}
this.$view[0].appendChild(l);
FR.HtmlLoader.loadingMoreData({
el: this.$view
});
this._setSelectedIndex(b);
this.fixWidth()
}
}
this.initContent= function(b, e, d) {
if (e == null) {
e = ""
}
var c = this;
b.height(this.options.sonHeight).attr("title", e).text(e).addClass(d > -1 ? "fr-combo-list-item" : "fr-combo-list-item fr-combo-list-item-noselect").hover(function(f) {
c.setFocusWithIndex(d);
setTimeout(function(h) {
if (!h) {
return
}
var g = a(h.target);
if (c.$view[0].style.display != "none" && g.isChildAndSelfOf(a(this).parent().children())) {
a(this).removeClass("fr-combo-selected")
}
}, 10)
}).click(function(f) {
c.inList = true;
c.fireEvent(FR.Events.CLICK);
c._setSelectedIndex(d);//修改事件为选中当前的index
c._onEnterPressed()
})
}
this._selectWithoutTriggerEvent= function() {
if (this.selectedIndex!=0) {
//如果不是第一个显示值
this.setText(this._getSelectedItem().text());
this.inList = true
} else {
//否者显示空
this.clearText();
this.searchText = "";
this.options.need2BuildList = true
}
this.checkValid();
this.collapse()
}