⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 autofinishinput.js

📁 OFFICE办公自动化
💻 JS
字号:
// JavaScript Document
function getvalue(smod,zd,key)
{
  var httpRequest;
  if (typeof XMLHttpRequest != 'undefined') {
      httpRequest = new XMLHttpRequest();
  }
  else if (typeof ActiveXObject != 'undefined') {
      httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
  }
  if (httpRequest) {
      httpRequest.open('GET', "../inc/getvalues.asp?smod="+smod+"&zd="+zd+"&key="+key, false);
      httpRequest.send(null);
      if(httpRequest.status == 200)
      {
          var textInfo = httpRequest.responseBody;
          return reCode(textInfo);
      }
  }
}

glbEncode=new Array();
function reCode(b){
	var t=rsB(b);
	t=escape(t).replace(/%u/g,"").replace(/(.{2})(.{2})/g,"%$2%$1").replace(/%([A-Z].)%(.{2})/g,"@$1$2");
	t=t.split("@");
	var i=0,j=t.length,k;
	while(++i<j)
	{
		k=t[i].substring(0,4);
		if(!glbEncode[k])glbEncode[k]=escape(rsChar(eval("0x"+k))).substring(1,6);
		t[i]=glbEncode[k]+t[i].substring(4);
	}
	return unescape(t.join("%"));
}


//-----------------------------------------------------------------------------
function CLASS_AUOTCOMPLETE(ID){
  
    var me = this;

    this.contain = document.getElementById("__auto_complete_contain");
    this.handle = null;
    this.dropdown = false;
    this.stopChange = false;
    this.line = 0;
    this.selectIndex = -1;
    this.id = "";

    if(ID!=null&&typeof(ID)!=undefined){
        this.id = ID;
    }else{
        this.id = getNewId();
    }

    function getNewId(){
        return "ID_" + Math.random().toString().substring(2)
    }

    this.add = function(s){
        this.list[this.list.length] = s;
    }

    this.sort = function(){
        //sort
        shellSort(this.list);
    }

    this.show = function(flag){

        var contain = me.contain;                        
        if(contain==null||typeof(contain)=="undefined"){
            contain = document.createElement("div");
            var body = document.body;
            if(typeof(body)!="undefined"){
                body.appendChild(contain);
            }
            me.contain = contain;
        }
        if(flag==undefined||flag==null){
            flag = true;
        }

        if(flag){                
            var w=1000,h=50,l,t;
            me.line = 0;
            if(me.handle!=null&&typeof(me.handle)!="undefined"){
                var v = me.handle.value;
                if(me.list!=null&&typeof(me.list)!="undefined"){
                    for(var i=contain.childNodes.length-1;i>=0;i--){
                        contain.removeChild(contain.childNodes[i]);
                    }
                    var index = 0;
                    for(var i=0;i<me.list.length;i++){
                        if(me.list[i].indexOf(v)==0){
                            var oo = document.createElement("div");
                            contain.appendChild(oo);
                            oo.innerText = me.list[i];
                            oo.style.height = "16px";
                            oo.style.width = "100%";
                            oo.style.overflow="hidden";
                            oo.style.lineHeight="120%";
                            oo.style.cursor = "hand";
                            oo.style.fontSize = "9pt";
                            oo.style.padding = "0 2 0 2";
                            oo.setAttribute("accoc",me.id + "__auto_complete_contain");
                            oo.setAttribute("sIndex",index);
                            oo.onmouseover = function(){
                                this.style.background = "highlight";
                                this.style.color = "highlighttext";
                                if(me.selectIndex>=0&&me.selectIndex!=this.getAttribute("sIndex")*1){
                                    var oc = me.contain.childNodes[me.selectIndex];
                                        oc.style.background = "#ffffff";
                                        oc.style.color = "#000000";
                                }
                                me.selectIndex = this.getAttribute("sIndex")*1;
                            }
                            oo.onmouseout = function(){
                                this.style.background = "#ffffff";
                                this.style.color = "#000000";
                            }
                            oo.onclick=function(){
                                me.stopChange = true;
                                me.handle.value = this.innerText;
                                me.stopChange = false;
                                me.show(false);                                     
                                var r =me.handle.createTextRange(); 
                                r.moveStart('character',me.handle.value.length); 
                                r.collapse(true); 
                                r.select();
                                me.handle.focus();
                                me.selectIndex = -1;
                            }
                            oo.onfocus = function(){ me.handle.focus();}
                            oo.onblur = me.handle.onblur;
                            oo.onselectstart    = function(){return false;};
                            me.line++;
                            index++;
                        }
                    }

                }
                w = me.handle.getBoundingClientRect().right - me.handle.getBoundingClientRect().left;
                l = me.handle.getBoundingClientRect().left;
                t = me.handle.getBoundingClientRect().bottom-1;
            }

            h = (me.line>6?6*16:me.line*16)+2;

            contain.style.position = "absolute";
            contain.style.top = t;
            contain.style.left = l;
            contain.style.width = w;
            contain.style.height = h;
            contain.style.overflowY    = "auto";
            contain.style.overflowX = "hidden";      
            contain.style.backgroundColor = "#ffffff";
            contain.style.border = "1px solid black";
            contain.setAttribute("accoc",me.id + "__auto_complete_contain");
            contain.onblur = me.handle.onblur;
            contain.onselectstart    = function(){return false;}
            contain.onfocus = function(){ me.handle.focus();}

            if(me.line<=0){
                contain.style.display = "none";
            }else{
                contain.style.display = "";
            }

        }else{
            contain.style.display = "none";
        }
        this.dropdown = flag;
    }

    this.filter = function(){
    	if(me.handle.value!=""){
    		this.list = getvalue(me.handle.getAttribute("smod"),me.handle.getAttribute("zd"),me.handle.value).split("|");
    		shellSort(this.list);
	        this.show();
	    }
    }

    this.getText = function(){
        if(me.selectIndex>=0){
            me.handle.value = me.contain.childNodes[me.selectIndex].innerText;
            me.show(false);
            var r =me.handle.createTextRange(); 
            r.moveStart('character',me.handle.value.length); 
            r.collapse(true); 
            r.select();
            me.handle.focus();
            me.selectIndex = -1;
        }
    }    

    this.move = function(flag){
        var osid = me.selectIndex;

        if(me.dropdown==false){
            me.show(true);
        }
        if(flag){
            me.selectIndex++;
        }else{
            me.selectIndex--;
        }
        if(me.selectIndex>me.contain.childNodes.length-1){
            me.selectIndex = 0;
        }
        if(me.selectIndex<0){
            me.selectIndex = me.contain.childNodes.length-1;
        }

        if(osid>=0){
            var d = me.contain.childNodes[osid];
            if(d!=null&&typeof(d)!="undefined"){
                d.style.background = "#ffffff";
                d.style.color = "#000000";
            }
        }
      
        if(me.selectIndex>=0){
            var c = me.contain.childNodes[me.selectIndex];
            if(c!=null&&typeof(c)!="undefined"){
                c.style.background = "highlight";
                c.style.color = "highlighttext";
                c.scrollIntoView(false);
            }
        }
    }

    this.setup = function(o){
        //this.list = o.getAttribute("autolist").split("|");
        //sort
        //shellSort(this.list);
        this.list = "";
        o.setAttribute("accoc",me.id + "__auto_complete_contain");
        this.handle = o;
        o.onpropertychange = function(){
            if(event.propertyName=="value"){
                if(me.stopChange==false){
                    me.filter();
                }
            }
        }
        o.ondblclick = function(){
            me.filter();
        }
        o.onkeydown= function(){
            switch(event.keyCode){
                case 38://up
                    me.move(false);
                    break;
                case 40://down
                    me.move(true);
                    break;
                case 13:
                    me.getText();
                    return false
                    break;
                default:
                    //alert(event.keyCode);
            }
        }
        o.onblur=function(){
            var active = document.activeElement;
            var stopHide = false;

            if(active!=null){
                var ac = active.getAttribute("accoc");
                if(ac!=null&&typeof(ac)!="undefined"&&ac==me.id + "__auto_complete_contain"){    
                    stopHide = true;
                }
            }
            if(stopHide==false){
                me.show(false);
            }
        }
    }

    function shellSort(arr){
        for (var step = arr.length >> 1; step > 0; step >>= 1){
            for (var i = 0; i < step; ++i){
                for (var j = i + step; j < arr.length; j += step){
                    var k = j, value = arr[j];
                    while (k >= step && arr[k - step] > value){
                        arr[k] = arr[k - step];
                        k -= step;
                    }
                    arr[k] = value;
                }
            }
        }
    }
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -