<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        javascriptxml為數據源的下拉框控件_javascript技巧

        來源:懂視網 責編:小采 時間:2020-11-27 20:43:22
        文檔

        javascriptxml為數據源的下拉框控件_javascript技巧

        javascriptxml為數據源的下拉框控件_javascript技巧:例如,當你在輸入框中輸入張三或是長沙,或是湖南,都會出現張三讓你選擇,輸入18,將同時出現張三李四 測試數據源如下: 代碼如下: s1 張三 湖南 長沙 18 s2 李四 湖北 武漢 18 s3 王五 四川 成都 20 //------------------
        推薦度:
        導讀javascriptxml為數據源的下拉框控件_javascript技巧:例如,當你在輸入框中輸入張三或是長沙,或是湖南,都會出現張三讓你選擇,輸入18,將同時出現張三李四 測試數據源如下: 代碼如下: s1 張三 湖南 長沙 18 s2 李四 湖北 武漢 18 s3 王五 四川 成都 20 //------------------

        例如,當你在輸入框中輸入張三或是長沙,或是湖南,都會出現張三讓你選擇,輸入18,將同時出現張三李四
        測試數據源如下:
        代碼如下:



        s1
        張三
        湖南
        長沙
        18


        s2
        李四
        湖北
        武漢
        18


        s3
        王五
        四川
        成都
        20



        //---------------------------------------------DropDownListx.js------------------------
        function DropDownListx(parent,id)
        {
        this.id = id;
        var i;
        var me = this;
        this.parent = parent;
        var e = this.parent;
        var y = e.offsetTop;
        var x = e.offsetLeft;
        this.text = e.value;
        while (e = e.offsetParent)
        {
        y += e.offsetTop;
        x += e.offsetLeft;
        }
        this.parentInfo = {x:0,y:0};
        this.parentInfo.x = x;
        this.parentInfo.y = y;
        //外觀
        this.width = this.parent.offsetWidth;
        this.height = 150;
        this.disabled = false;
        this.visibility = "hidden";
        this.attributed = false;//數據是否以屬性表示,也可以用node來表示
        this.mainText = "";//要顯示的字段名字
        this.mainValue = "";//要返回的值的字段名字
        this.selectedIndex = -1;//被選中的索引
        this.mouseoverIndex = -1;//鼠標懸停時的索引
        this.mouseoutIndex = -1;//鼠標離開時的索引
        this.selectedValue = "";
        this.selectedText = "";
        this.value = "";
        this.text = "";
        this.drawed = false;//表示是否重繪過
        this.table = null;
        //數據源
        this.dataSource = null;
        try
        {
        for(i = 6;i>0;i--)
        {
        try
        {
        this.dataSource = new ActiveXObject("MSXML2.DOMDocument." + i + ".0");
        break;
        }
        catch(ex1){;};
        }
        }
        catch(ex2){;};
        this.dataSource.async = false;
        this.dataSource.setProperty("SelectionLanguage", "XPath");
        var sh = function(){if(me.visibility == "hidden")me.show();};
        this.parent.attachEvent("onfocus",function(){window.setTimeout(sh,100);});
        this.parent.attachEvent("onchange",function(){me.filter(me.parent.value);});
        this.parent.attachEvent("onkeyup",function(){me.filter(me.parent.value);});
        this.parent.attachEvent("onclick",function(){if(event.button == "1")window.setTimeout(sh,10);});
        this.parent.style.cursor = "hand";
        //事件
        this.onSelected=null;
        this.onmouseover = null;
        this.onmouseout = null;
        this.onhide = null;
        window.document.attachEvent("onclick",function()
        {
        //有可能e不在最上層,所以要找到牠的區域
        if(event.x < me.parentInfo.x ||
        event.x > me.parentInfo.x + me.parent.offsetWidth ||
        event.y < me.parentInfo.y ||
        event.y > me.parentInfo.y + me.parent.offsetHeight)
        {
        if(me.visibility == "visible")
        me.hide();
        }
        });
        }
        //重新獲取位置,因爲parent的位置可能變動
        DropDownListx.prototype.getPosition=function()
        {
        var e = this.parent;
        var y = e.offsetTop;
        var x = e.offsetLeft;
        while (e = e.offsetParent)
        {
        y += e.offsetTop;
        x += e.offsetLeft;
        }
        this.parentInfo = {x:0,y:0};
        this.parentInfo.x = x;
        this.parentInfo.y = y;
        this.width = this.parent.offsetWidth;
        }
        //畫出列表
        DropDownListx.prototype.show=function()
        {
        this.getPosition();
        var me = this;
        //畫一個div
        var divid = this.id + "_div_" + this.parent.id;
        var d = document.getElementById(divid);
        if(d==null)
        {
        d = document.createElement("div");
        d.style.position = "absolute";
        }
        d.style.borderLeft = "black 1px groove";
        d.style.borderTop = "black 1px groove";
        d.style.borderRight = "black 1px groove";
        document.body.appendChild(d);
        d.setAttribute("id",divid);
        d.style.borderBottom = "black 1px groove";
        d.style.backgroundColor = "white";
        d.style.left = this.parentInfo.x + "px";
        if(document.body.clientHeight < this.parentInfo.y + this.parent.offsetHeight + this.height)
        d.style.top = (this.parentInfo.y - this.height) + "px";
        else
        d.style.top = (this.parentInfo.y +( this.parent.offsetHeight==""?20:this.parent.offsetHeight)) + "px";
        d.style.overflowX = "hidden";
        d.style.overflowY = "auto";
        d.style.zIndex = 999;
        d.style.visibility = "visible";
        d.style.borderWidth = "1px";
        this.visibility = "visible";
        this.listData();
        this._selectByName(this.parent.value);
        }
        DropDownListx.prototype.listData=function()
        {
        var e = this.parent;
        var base = this;
        //顯示數據
        if(this.nodeList == null)
        this.nodeList = this.dataSource.documentElement.childNodes;
        var str="";
        for(var i = 0;i{
        var text = (base.attributed?this.nodeList.item(i).getAttribute(this.mainText):this.nodeList.item(i).selectSingleNode(this.mainText).text);
        str = str + "
        ";
        }
        str += "
        " + text + "
        ";
        var div = document.getElementById( this.id + "_div_" + e.id);
        div.innerHTML = str;
        var table = document.getElementById( this.id + "_table_" + e.id);
        this.table = table;
        if(table.offsetHeight < this.height)
        div.style.height = table.offsetHeight + 3;
        else
        div.style.height = this.height + 3;
        div.style.width = table.offsetWidth;
        for(var j = 0;j{
        var d = document.getElementById(this.id + "_td_" + j + "_" + e.id );
        d.attachEvent('onclick',function()
        {
        var _td = document.getElementById(base.id + "_td_" + base.selectedIndex + "_" + e.id);
        if(_td)
        {
        _td.style.backgroundColor = "";
        _td.style.color = "";
        }
        base.selectedIndex = event.srcElement.parentElement.rowIndex;
        document.getElementById(base.id + "_div_" + base.parent.id ).style.visibility="hidden";
        base.selectedValue = (base.attributed?base.nodeList.item(base.selectedIndex).getAttribute(base.mainValue):base.nodeList.item(base.selectedIndex).selectSingleNode(base.mainValue).text);
        base.selectedText = (base.attributed?base.nodeList.item(base.selectedIndex).getAttribute(base.mainText):base.nodeList.item(base.selectedIndex).selectSingleNode(base.mainText).text);
        base.value = base.selectedValue;base.text = base.selectedText;
        if(base.onSelected != null)
        base.onSelected.apply(base);
        return false;
        });
        d.onmouseover=function()
        {
        base.mouseoverIndex =parseInt(event.srcElement.id.split("_td_")[1].split("_")[0]);
        try
        {
        event.srcElement.style.backgroundColor='gray';
        event.srcElement.style.color='white';
        e.value = event.srcElement.innerText;
        if(base.onmouseover != null)
        base.onmouseover.apply(base);
        }
        catch(ex){};
        };
        d.onmouseout = function()
        {
        base.mouseoutIndex = parseInt(event.srcElement.id.split("_td_")[1].split("_")[0]);
        if(event.srcElement.id == base.id + "_td_" + base.selectedIndex + "_" + e.id)
        {
        event.srcElement.style.backgroundColor='red';
        event.srcElement.style.color='blue';
        }
        else
        {
        event.srcElement.style.backgroundColor='';
        event.srcElement.style.color='';
        }
        if(base.onmouseout != null)
        base.onmouseout.apply(base);
        }
        }
        this.drawed = true;
        }
        DropDownListx.prototype.hide=function()
        {
        var d = document.getElementById(this.id + "_div_" + this.parent.id);
        if(d)
        d.style.visibility = "hidden";
        this.visibility = "hidden";
        this._select(this.selectedIndex);//為了防止有篩選的數據,要先選擇
        this.nodeList = this.dataSource.documentElement.childNodes;
        if(this.onhide != null)
        this.onhide.apply(this);
        }
        DropDownListx.prototype.setSource=function(d)
        {
        this.dataSource.loadXML(d.xml);
        this.nodeList = d.documentElement.childNodes;
        this.drawed = false;
        }
        DropDownListx.prototype.setChildNodes=function(nodes)
        {
        this.dataSource.loadXML("");
        var node = this.dataSource.documentElement;
        for(var i = 0;i{
        var opt = doc.createNode(1,"option","");
        var r = nodes.item(i).childNodes
        for(var j = 0;j{
        var att = doc.createNode(1,r.item(j).nodeName,"");
        att.text = r.item(j).text;
        opt.appendChild(att);
        }
        node.appendChild(opt);
        }
        this.drawed = false;
        }
        DropDownListx.prototype.filter=function(text)
        {
        if(text==null || text =="")
        {
        this.reset();
        }
        else
        {
        var _text = text.split(" ");
        var str = "./*[contains(.,'" + _text[0] + "')";
        for(var i=1;i<_text.length;i++)
        {
        str = str + " and contains(.,'" + _text[i] + "')"
        }
        str = str + "]";
        this.nodeList = this.dataSource.documentElement.selectNodes(str);
        }
        this.listData();
        }
        //根據查詢選中的節點的子節點的值
        DropDownListx.prototype.getNodeValue=function(nodeName)
        {
        if(nodeName == null || nodeName == "")
        return this.value;
        return (this.attributed?this.nodeList.item(this.selectedIndex).getAttribute(nodeName):this.nodeList.item(this.selectedIndex).selectSingleNode(nodeName).text);
        }
        DropDownListx.prototype.reset=function()
        {
        this.nodeList = this.dataSource.documentElement.childNodes;
        var _td = document.getElementById(this.id + "_td_" + this.selectedIndex + "_" + this.parent.id);
        if(_td)
        {
        _td.style.backgroundColor = "";
        _td.style.color = "";
        }
        this.selectedIndex = -1;
        this.selectedValue = "";
        this.selectedText = "";
        this.value = "";
        this.text = "";
        this.parent.value = "";
        }
        DropDownListx.prototype.select=function(index)
        {
        if(index == -1)
        this.reset();
        else
        {
        var _td = document.getElementById(this.id + "_td_" + this.selectedIndex + "_" + this.parent.id);
        if(_td)
        {
        _td.style.backgroundColor = "";
        _td.style.color = "";
        }
        this.nodeList = this.dataSource.documentElement.childNodes;
        this.selectedIndex = index;//被選中的索引
        this.selectedValue = this.attributed?this.nodeList.item(index).getAttribute(this.mainValue):this.nodeList.item(index).selectSingleNode(this.mainValue).text;
        this.selectedText = this.attributed?this.nodeList.item(index).getAttribute(this.mainText):this.nodeList.item(index).selectSingleNode(this.mainText).text;
        this.value = this.selectedValue;
        this.text = this.selectedText;
        this.parent.value = this.selectedText;
        try
        {
        this.table.rows.item(index).cells.item(0).focus();
        this.table.rows.item(index).cells.item(0).style.backgroundColor = "red";
        this.table.rows.item(index).cells.item(0).style.color = "blue";
        this.parent.focus();
        }catch(ex){}
        if(this.onSelected != null)
        this.onSelected.apply(this);
        }
        }
        DropDownListx.prototype.selectByName=function(name)
        {
        if(name == null || name == "")
        {
        this.reset();
        return;
        }
        for(var i = 0;i{
        var _name = this.attributed?this.nodeList.item(i).getAttribute(this.mainText):this.nodeList.item(i).selectSingleNode(this.mainText).text;
        if(_name == name) break;
        }
        if(i != this.nodeList.length)
        {
        this.select(i);
        }
        else
        this.reset();
        }
        DropDownListx.prototype.selectByValue=function(value)//不響應事件的副本
        {
        if(value == null || value == "")
        {
        this.reset();
        return;
        }
        for(var i = 0;i{
        var _value = this.attributed?this.nodeList.item(i).getAttribute(this.mainValue):this.nodeList.item(i).selectSingleNode(this.mainValue).text;
        if(_value == value) break;
        }
        if(i != this.nodeList.length)
        {
        this.select(i);
        }
        else
        this.reset();
        }
        DropDownListx.prototype._select=function(index)//不響應事件的副本
        {
        if(index == -1)
        this.reset();
        else
        {
        var _td = document.getElementById(this.id + "_td_" + this.selectedIndex + "_" + this.parent.id);
        if(_td)
        {
        _td.style.backgroundColor = "";
        _td.style.color = "";
        }
        //this.nodeList = this.dataSource.documentElement.childNodes;
        this.selectedIndex = index;//被選中的索引
        this.selectedValue = this.attributed?this.nodeList.item(index).getAttribute(this.mainValue):this.nodeList.item(index).selectSingleNode(this.mainValue).text;
        this.selectedText = this.attributed?this.nodeList.item(index).getAttribute(this.mainText):this.nodeList.item(index).selectSingleNode(this.mainText).text;
        this.value = this.selectedValue;
        this.text = this.selectedText;
        this.parent.value = this.selectedText;
        try
        {
        this.table.rows.item(index).cells.item(0).focus();
        this.table.rows.item(index).cells.item(0).style.backgroundColor = "red";
        this.table.rows.item(index).cells.item(0).style.color = "blue";
        this.parent.focus();
        }catch(ex){}
        }
        }
        DropDownListx.prototype._selectByName=function(name)//不響應事件的副本
        {
        if(name == null || name == "")
        {
        this.reset();
        return;
        }
        for(var i = 0;i{
        var _name = this.attributed?this.nodeList.item(i).getAttribute(this.mainText):this.nodeList.item(i).selectSingleNode(this.mainText).text;
        if(_name == name) break;
        }
        if(i != this.nodeList.length)
        {
        this._select(i);
        }
        else
        this.reset();
        }
        DropDownListx.prototype._selectByValue=function(value)//不響應事件的副本
        {
        if(value == null || value == "")
        {
        this.reset();
        return;
        }
        for(var i = 0;i{
        var _value = this.attributed?this.nodeList.item(i).getAttribute(this.mainValue):this.nodeList.item(i).selectSingleNode(this.mainValue).text;
        if(_value == value) break;
        }
        if(i != this.nodeList.length)
        {
        this._select(i);
        }
        else
        this.reset();
        }
        //---------------------------------------------DropDownListx-vsdoc.js------------------------
        ///
        function DropDownListx(parent, id)
        {
        ///
        /// 自定義的下拉框類
        ///

        ///
        ///
        /// 下柆框的父控件,只能是文本輸入框元素;
        ///
        ///
        ///
        /// 下拉框的ID的文本
        ///
        }
        DropDownListx.prototype =
        {
        getPosition: function()
        {
        ///
        /// 重新獲取下拉框的位置,因為parent的位置可能會變動
        ///

        },
        show: function()
        {
        ///
        /// 顯示下拉框
        ///

        },
        listData: function()
        {
        ///
        /// 繪制下拉框
        ///

        },
        hide: function()
        {
        ///
        /// 隱藏下拉框
        ///

        },
        setSource: function(d)
        {
        ///
        /// 設置下拉框xml數據源
        ///

        ///
        /// 要指定的下拉框的xml數據源
        ///
        },
        setChildNodes: function(nodes)
        {
        ///
        /// 設置下拉框xml數據源
        ///

        ///
        /// 要指定的下拉框的xml節點集
        ///
        },
        filter: function(text)
        {
        ///
        /// 對下拉框進行全局篩選
        ///

        ///
        /// 要查找的文枉
        ///
        },
        getNodeValue: function(nodeName)
        {
        ///
        /// 返回選中節點對應的子節點的值
        ///

        ///
        /// 子節點名
        ///
        },
        reset: function()
        {
        ///
        /// 重置下拉框
        ///

        },
        select: function(index)
        {
        ///
        /// 按索引進行選擇
        ///

        ///
        /// 索引值
        ///
        },
        selectByName:function(name)
        {
        ///
        /// 按文本進行選擇
        ///

        ///
        /// 要選擇的文本,此值將會與mainText屬性所對應的節點進行對比
        ///
        },
        selectByValue:function(value)
        {
        ///
        /// 按值進行選擇
        ///

        ///
        /// 要選擇的值,此值將會與mainValue屬性所對應的節點進行對比
        ///
        },
        _select:function(index)
        {
        ///
        /// 按索引進行選擇,select方法不響應事件的副本
        ///

        ///
        /// 索引值
        ///
        },
        _selectByName:function(name)
        {
        ///
        /// 按文本進行選擇,selectByName方法不響應事件的副本
        ///

        ///
        /// 要選擇的文本,此值將會與mainText屬性所對應的節點進行對比
        ///
        },
        _selectByValue:function(value)
        {
        ///
        /// 按值進行選擇,selectByValue方法不響應事件的副本
        ///

        ///
        /// 要選擇的值,此值將會與mainValue屬性所對應的節點進行對比
        ///
        }
        }

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        javascriptxml為數據源的下拉框控件_javascript技巧

        javascriptxml為數據源的下拉框控件_javascript技巧:例如,當你在輸入框中輸入張三或是長沙,或是湖南,都會出現張三讓你選擇,輸入18,將同時出現張三李四 測試數據源如下: 代碼如下: s1 張三 湖南 長沙 18 s2 李四 湖北 武漢 18 s3 王五 四川 成都 20 //------------------
        推薦度:
        標簽: js 下拉列表 控件
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 成年女人视频网站免费m| 免费人妻无码不卡中文字幕系| 三年片在线观看免费大全| 亚洲成a人片在线观看中文app| 最近中文字幕无免费| 亚洲美女中文字幕| 黄+色+性+人免费| 亚洲sss综合天堂久久久| 国产在线国偷精品产拍免费| 亚洲欧洲国产综合AV无码久久| 国产美女被遭强高潮免费网站 | 免费日本黄色网址| 亚洲欧美国产日韩av野草社区| 毛片a级三毛片免费播放| 国产精品亚洲专区无码WEB| 免费大黄网站在线看| 国产99视频精品免费视频76| 亚洲色图.com| 国产人成免费视频网站| 中文日韩亚洲欧美制服| 国产一区二区三区免费看| 国产国产人免费人成成免视频| 国产亚洲综合久久系列| 18禁黄网站禁片免费观看不卡| 亚洲一区AV无码少妇电影| 免费一级毛片在线播放| a毛片在线免费观看| 亚洲伦理中文字幕| 亚洲精品国产福利一二区| 一级成人a毛片免费播放| 亚洲日韩乱码中文字幕| 国产日韩成人亚洲丁香婷婷| 57pao国产成永久免费视频| 日本亚洲欧美色视频在线播放| 亚洲色成人网站WWW永久| 国产香蕉免费精品视频| 男人和女人高潮免费网站| 亚洲成人一级电影| 亚洲线精品一区二区三区| 欧美大尺寸SUV免费| 免费无码av片在线观看 |