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

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

GooFunc.js文件


//获取一个DIV的绝对坐标的功能函数,即使是非绝对定位,一样能获取到
function getElCoordinate(dom) {
var t = dom.offsetTop;
var l = dom.offsetLeft;
dom=dom.offsetParent;
while (dom) {
t += dom.offsetTop;
l += dom.offsetLeft;
dom=dom.offsetParent;
}; return {
top: t,
left: l
};
}
//兼容各种浏览器的,获取鼠标真实位置
function mousePosition(ev){
if(!ev) ev=window.event;
if(ev.pageX || ev.pageY){
return {x:ev.pageX, y:ev.pageY};
}
return {
x:ev.clientX + document.documentElement.scrollLeft - document.body.clientLeft,
y:ev.clientY + document.documentElement.scrollTop - document.body.clientTop
};
}
//给DATE类添加一个格式化输出字串的方法
Date.prototype.format = function(format)
{
var o = {
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second ‘
//quarter
"q+" : Math.floor((this.getMonth()+3)/3),
"S" : this.getMilliseconds() //millisecond
}
if(/(y+)/.test(format)) format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
for(var k in o)if(new RegExp("("+ k +")").test(format))
format = format.replace(RegExp.$1,
RegExp.$1.length==1 ? o[k] :
("00"+ o[k]).substr((""+ o[k]).length));
return format;
}

<pre name="code" class="javascript"><pre name="code" class="javascript"><pre name="code" class="javascript"><pre name="code" class="javascript">GooCombo.JS文件</pre>
<pre></pre>
<pre></pre>
<pre></pre>
<pre name="code" class="javascript">/*下拉框定义--GooCombo类*/
//dom :要被绑定的DOM对象,必须要有其ID或者NAME,且未被JQUERY对象化
//property :JSON变量,SLIDER的详细参数设置
//目前,构造函数可接受用普通DOM容器或者直接传送SELECT控件来进行渲染
function GooCombo(dom,property){
this.$div=null;//渲染完毕后最父框架的DIV
this.$id=null;//this.$div中SELECT控件的ID
this.$name=null;//this.$div中SELECT控件的NAME
this.$width = property.width; //下拉框控件的宽度,必填项

this.$haveIcon=property.haveIcon||false;
this.$input = $("<input type='text' value='" + property.text + "' " + (property.readOnly ? "readonly='readonly'" : "") + (this.$haveIcon ? " style='margin-left:20px;width:" + (this.$width - 39) + "px'" : "") + "/>"); //下拉框控件中始终显示的文本框INPUT
this.$btn=$("<div class='btn_up'></div>");//下拉框右部的按钮
this.$data=[];//下拉框控件的所有显示文字和值,二维数组