可输入文字查找ajax下拉框控件 ComBox的实现方法

2020-05-27 18:00:48易采站长站整理

elsethis.$select.removeAttr("multiple");
}
//载入一组数据的方法
this.loadListData = function (data) {
this.$data = [];
if (this.$list.children("a").length > 0) {
this.$list.empty();
this.$select.empty();
}
temp = "", temp2 = "";
for (i = 0; i < data.length; ++i) {
this.$data[i] = [data[i][0], data[i][1], data[i][2] || ""];
if (this.$type== "filter")//在这里可以修改你想类型 basic 当鼠标点击进去是否展现初始数据
temp += "<a href='#'><p " + (this.$haveIcon ? "style='text-indent:19px;background:" + this.$data[i][2] + "' " : "") + "value='" + this.$data[i][0] + "'>" + this.$data[i][1] + "</p></a>";
temp2 += "<option value='" + this.$data[i][0] + "'>" + this.$data[i][1] + "</option>";
}
if (this.$type == "filter")

this.$list.append(temp);
this.$select.append(temp2);
this.$alreadyLoad = true;
};
if(property.data)this.loadListData(property.data);
//动态远程载入数据,AJAX请求的参数将读取this.$ajaxType中的设置
this.loadListDataAjax=function(){
var inthis=this;
$.ajax({
type:this.$ajaxType.type,
url:this.$ajaxType.url,
dataType:this.$ajaxType.dataType,
data:this.$ajaxType.para,
success:function(data){
inthis.loadListData(data);
}});

};

//提示文字
$("input[type='text']").each(function () {
if ($(this).val() == property.text) {
$(this).bind("focus", function () {
$(this).val("");
}).blur(function () {
$(this).val(property.text)
});

}
});

//绑定当INPUT框被选中时的事件
this.$input.bind("focus", { inthis: this }, //如果this.$autoLoad或!this.$alreadyLoad有一个为FALSE,则ajaxType将无效,可不传
function (e) {
if (e && e.preventDefault) e.preventDefault(); //阻止默认浏览器动作(W3C)
else window.event.returnValue = false; //IE中阻止函数器默认动作的方式
var inthis = e.data.inthis;
// inthis.$autoLoad = true;
//
//
// inthis.$alreadyLoad = false;
// inthis.$ajaxType = false;
if (!inthis.$alreadyLoad && inthis.$autoLoad) {

if (inthis.$ajaxType) {//如果是远程AJAX获取数据

inthis.loadListDataAjax();
}
else
{
inthis.loadListData(inthis.$data);
}

}
var list = inthis.$list;

var height = inthis.$selectHeight;
var width = inthis.$width;
list.css("display", "block");
$(document).bind("mouseup", function (e) {
var locate = getElCoordinate(list.get(0));
var ev = mousePosition(e);
if (locate.left + width < ev.x || locate.left > ev.x || locate.top - 22 > ev.y || locate.top + height + 2 < ev.y) {
list.css("display", "none");
}
this.onmouseup = null;