公交车上荫蒂添的好舒服的电影-公用玩物(np双xing总受)-公用小荡货芊芊-公与妇仑乱hd-攻把受做哭边走边肉楼梯play-古装一级淫片a免费播放口

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發文檔 其他文檔  
 
網站管理員

仿百度文本輸入框自動補全智能提示效果

admin
2011年2月19日 14:18 本文熱度 3731

就像百度的搜索框一樣,當用戶在文本框輸入前幾個字母或是漢字的時候,該控件就能從存放數據的文或是數據庫里將所有以這些字母開頭的數據提示給用戶,供用戶選擇,提供方便,增加用戶體驗。


本代碼在IE6 IE7 IE8 和firefox 3.6.8 中測試通過。


var autoComplete=new AutoComplete(arg1,arg2,arg3);
AutoComplete對象中的三個參數 說明一下:
arg1: 搜索框的ID (類型:字符串)
arg2:自動補全DIV根節點的ID(類型:字符串)
arg3:待匹配的數據 (類型:數組)



HTML code
 
 
<!doctype html>
<html>
<style>
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
.auto_hidden {
    width:204px;border-top: 1px solid #333;
    border-bottom: 1px solid #333;
    border-left: 1px solid #333;
    border-right: 1px solid #333;
    position:absolute;
    display:none;
}
.auto_show {
    width:204px;
    border-top: 1px solid #333;
    border-bottom: 1px solid #333;
    border-left: 1px solid #333;
    border-right: 1px solid #333;
    position:absolute;
    z-index:9999; /* 設置對象的層疊順序 */
    display:block;
}
.auto_onmouseover{
    color:#ffffff;
    background-color:highlight;
    width:100%;
}
.auto_onmouseout{
    color:#000000;
    width:100%;
    background-color:#ffffff;
}
</style>

<script language="javascript">
<!--
/*
通用: 自動補全(仿百度搜索框)
作者:nj-troy
時間:2010-11-101
*/

var $ = function (id) {
    return "string" == typeof id ? document.getElementById(id) : id;
}
var Bind = function(object, fun) {
    return function() {
        return fun.apply(object, arguments);
    }
}
function AutoComplete(obj,autoObj,arr){
    this.obj=$(obj);        //輸入框
    this.autoObj=$(autoObj);//DIV的根節點
    this.value_arr=arr;        //不要包含重復值
    this.index=-1;          //當前選中的DIV的索引
    this.search_value="";   //保存當前搜索的字符
}
AutoComplete.prototype={
    //初始化DIV的位置
    init: function(){
        this.autoObj.style.left = this.obj.offsetLeft + "px";
        this.autoObj.style.top  = this.obj.offsetTop + this.obj.offsetHeight + "px";
        this.autoObj.style.width= this.obj.offsetWidth - 2 + "px";//減去邊框的長度2px  
    },
    //刪除自動完成需要的所有DIV
    deleteDIV: function(){
        while(this.autoObj.hasChildNodes()){
            this.autoObj.removeChild(this.autoObj.firstChild);
        }
        this.autoObj.className="auto_hidden";
    },
    //設置值
    setValue: function(_this){
        return function(){
            _this.obj.value=this.seq;
            _this.autoObj.className="auto_hidden";
        }      
    },
    //模擬鼠標移動至DIV時,DIV高亮
    autoOnmouseover: function(_this,_div_index){
        return function(){
            _this.index=_div_index;
            var length = _this.autoObj.children.length;
for(var j=0;j<length;j++){
                if(j!=_this.index ){      
                    _this.autoObj.childNodes[j].className='auto_onmouseout';
                }else{
                    _this.autoObj.childNodes[j].className='auto_onmouseover';
                }
            }
        }
    },
    //更改classname
    changeClassname: function(length){
        for(var i=0;i<length;i++){
            if(i!=this.index ){      
                this.autoObj.childNodes[i].className='auto_onmouseout';
            }else{
                this.autoObj.childNodes[i].className='auto_onmouseover';
                this.obj.value=this.autoObj.childNodes[i].seq;
            }
        }
    }
    ,
    //響應鍵盤
    pressKey: function(event){
        var length = this.autoObj.children.length;
        //光標鍵"↓"
        if(event.keyCode==40){
            ++this.index;
            if(this.index>length){
                this.index=0;
            }else if(this.index==length){
                this.obj.value=this.search_value;
            }
            this.changeClassname(length);
        }
        //光標鍵"↑"
        else if(event.keyCode==38){
            this.index--;
            if(this.index<-1){
                this.index=length - 1;
            }else if(this.index==-1){
                this.obj.value=this.search_value;
            }
            this.changeClassname(length);
        }
        //回車鍵
        else if(event.keyCode==13){
            this.autoObj.className="auto_hidden";
            this.index=-1;
        }else{
            this.index=-1;
        }
    },
    //程序入口
    start: function(event){
        if(event.keyCode!=13&&event.keyCode!=38&&event.keyCode!=40){
            this.init();
            this.deleteDIV();
            this.search_value=this.obj.value;
            var valueArr=this.value_arr;
            valueArr.sort();
            if(this.obj.value.replace(/(^\s*)|(\s*$)/g,'')==""){ return; }//值為空,退出
            try{ var reg = new RegExp("(" + this.obj.value + ")","i");}
            catch (e){ return; }
            var div_index=0;//記錄創建的DIV的索引
            for(var i=0;i<valueArr.length;i++){
                if(reg.test(valueArr[i])){
                    var div = document.createElement("div");
                    div.className="auto_onmouseout";
                    div.seq=valueArr[i];
                    div.onclick=this.setValue(this);
                    div.onmouseover=this.autoOnmouseover(this,div_index);
                    div.innerHTML=valueArr[i].replace(reg,"<strong>$1</strong>");//搜索到的字符粗體顯示
                    this.autoObj.appendChild(div);
                    this.autoObj.className="auto_show";
div_index++; } } }
this.pressKey(event);
        window.onresize=Bind(this,function(){this.init();});
    }
}
//-->
</SCRIPT>

<body>
<h1 align="center">自動完成函數(Autocomplete Function)</h1>
    <div align="center"><input type="text" style="width:300px;height:20px;font-size:14pt;" id="o" onkeyup="autoComplete.start(event)"></div>
    <div class="auto_hidden" id="auto"><!--自動完成 DIV--></div>
<script>
    var autoComplete=new AutoComplete('o','auto',['b0','b12','b22','b3','b4','b5','b6','b7','b8','b2','abd','ab','acd','accd','b1','cd','ccd','cbcv','cxf']);
</SCRIPT>

</body>
</html>

該文章在 2011/2/19 14:18:43 編輯過
關鍵字查詢
相關文章
正在查詢...
點晴ERP是一款針對中小制造業的專業生產管理軟件系統,系統成熟度和易用性得到了國內大量中小企業的青睞。
點晴PMS碼頭管理系統主要針對港口碼頭集裝箱與散貨日常運作、調度、堆場、車隊、財務費用、相關報表等業務管理,結合碼頭的業務特點,圍繞調度、堆場作業而開發的。集技術的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業的高效ERP管理信息系統。
點晴WMS倉儲管理系統提供了貨物產品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質期管理,貨位管理,庫位管理,生產管理,WMS管理系統,標簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務都免費,不限功能、不限時間、不限用戶的免費OA協同辦公管理系統。
Copyright 2010-2025 ClickSun All Rights Reserved

主站蜘蛛池模板: 国产美女亚洲真人做受在线观看 | 91亚洲中文天堂在线观看 | www.毛片| 国产aⅴ无码精品一区二区三区 | 国产一区在线观看不卡 | 国产成人av在线播放欲色 | 丰满成熟少妇a级毛片 | 国产超级大爆乳美女在线播放 | 国产成人三级在线播放 | 国产精品无码电影在线观看 | 国产av人人夜 | 精品国产免费入口 | 国产亚洲欧美日韩一区午夜电影 | 波多野结衣人妻在线一区二区 | 91福利国产在线在线播放 | 国产成人啪精品视频免费a 国产成人啪精品视频免费软件 | 国产v亚洲v天堂a无码99 | 国产一区三区二区中文在线 | 91人妻人人澡人人爽人人精 | 爆爽久久久一区二区又大又黄又嫩 | 精品国产三级国产av中文 | 国产av+刺激+无码 | 99精品国产免费久久国语 | 91久久久久国产一区二区 | 国产成人精品777 | 国产欧美激情黄片 | a视频在线观看无码 | 岛国一区二区三区在线观看 | 国产美女高潮抽搐流水在线看 | 国产午夜精品理论片久久影院 | 成人亚洲一区无码久久 | 精品91自产拍 | av免费午夜电影在线看 | av在线最新网址不卡 | 国产高清美女一级毛片久久 | 韩国三级伦在线观看久 | 国产成人综合久久免费导航 | 国产精品一级特黄毛片 | 丰满人妻一区二区三区46 | 高清无码喷水一区 | 国产女主播野外在线观看 |