ZhipSoft.com
              冬去春來
                  鄭重聲明:本Blog純屬個(gè)人學(xué)習(xí)、工作需要,記錄相關(guān)資料。請(qǐng)不要發(fā)表任何有人身攻擊的言論,謝謝!!www.ZhipSoft.com
          posts - 94,comments - 149,trackbacks - 0

          <html>
          <!--函數(shù)說明:可輸入的下拉框列表改進(jìn)第二版.
          基本參考的阿信的"可輸入下拉框第二版",不過將調(diào)用接口改進(jìn)了,并允許用戶為控件命名,方便大家在項(xiàng)目中調(diào)用.

          接口說明:
          1: addSelect(obj_id,DefaultValue) 增加空的select控件
          參數(shù)說明:
          obj_id: 控件的id號(hào).
          DefaultValue: 缺省值.
          2: addOption(value,ID) 增加option列表
          參數(shù)說明:
          value: 下拉列表中每一項(xiàng)的值
          ID: 如果存在多個(gè)控件,第一個(gè)控件的ID值為0,第二個(gè)為1,一此類推.


          使用說明:將源代碼中<style>與</style>之間的代碼和<script>與</script>之間的代碼拷貝到你需要調(diào)用該控件的頁(yè)面的相應(yīng)位置.然后在需要顯示控件的地方調(diào)用上面兩個(gè)接口.
          -->
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
          <title>可輸入的下拉框改進(jìn)第二版</title>
          <style>
          .selectBox{
           border-top-color : #7C7C7C;
           border-left-color : #7C7C7C;
           border-right-color : #D0D0D0;
           border-bottom-color : #D0D0D0;
           border-top-width: 2px;
           border-right-width: 1px;
           border-bottom-width: 1px;
           border-left-width: 2px;
           border-top-style: solid;
           border-right-style: solid;
           border-bottom-style: solid;
           border-left-style: solid;
          }
          .editBox{
           border:0px;
           width:100%;
           cursor:default;
           width:100%;
           padding-top:2px;
           margin-top: 1px;
           margin-right: auto;
           margin-bottom: 1px;
           margin-left: auto;
          }
          .dropdownbutton{
           font-size:12px;
           font-family:webdings;
           color:#000000;
           background-color:#D4D0C8;
           margin:1px;
           cursor:default;
           border-top-width: 2px;
           border-right-width: 2px;
           border-bottom-width: 2px;
           border-left-width: 2px;
           border-top-style: solid;
           border-right-style: solid;
           border-bottom-style: solid;
           border-left-style: solid;
           border-top-color: #E4E4E4;
           border-right-color: #7C7C7C;
           border-bottom-color: #7C7C7C;
           border-left-color: #E4E4E4;
           padding-top: 0px;
           padding-right: 2px;
           padding-bottom: 0px;
           padding-left: 2px;
          }
          .selectContent{
           position:absolute;
           visibility:hidden;
           z-index:1000;
           background-color:#FFFFFF;
           border: 1px solid #000000;
          }
          .selectContent tr{cursor:default}
          .selectContent td{
           font-size:12px;
           font-family:Vendana;
           padding-top: 2px;
           padding-right: 3px;
           padding-bottom: 2px;
           padding-left: 3px;
          }
          .OnFocus{color:#FFFFFF;background-color:#0A246A}
          </style>
          <script language="javascript">
          var ZfSelect=[]
          var CurrentTR=null
          function String.prototype.Trim(){return this.replace(/(^\s*)|(\s*$)/g,'')}//自定義去空格函數(shù)Trim()
          //在第ID個(gè)控件下增加option選項(xiàng)
          function addOption(v,ID) {
           
           var i=ID+1;
           //var sv=document.all['ZfSelect_'+ID];
           if(!v.Trim())
           {
           return;
           }
           var tb=document.all['ZfSelect'+i];
          // var test = 'ZfSelect' + i;
          // var tb = document.all[test];
          // alert(tb);
          // alert(document.all['ZfSelect'+i]);
           //tb.insertRow();
           //alert(tb.id);return;
           // tb.rows.length 代表有幾行數(shù)據(jù)
           
           var c=tb.insertRow(tb.rows.length).insertCell();
           // 下拉列表中的顯示值 c.innerHTML
           c.innerHTML=v.Trim();
           
           c.onmouseover=new Function("MouseOver(this)");

           c.onmouseout=new Function("out(this)");

           c.onclick=new Function("MouseClick("+ID+",this)");

           //c.className="td_out";
           v='';
          }
          //增加inpnubox的接口,在頁(yè)面中產(chǎn)生一個(gè)inputbox控件,下拉列表為空
          function addSelect(name,DefValue) {  
           var i=getSelCount();
            
           var j=i+1;
           //alert("i is:"+i);
           var str='<table id="ZfContainer'+j+'" class="selectBox" border="0" width=100 cellspacing=0 cellpadding=0><tr><td><input name="'+name+'" value="'+DefValue+'" class="editBox" onblur="BoxBlur(this)" onclick="DropDown('+i+')" onkeyup="showTip('+i+')" onmouseenter="selectmove()" onmouseout="selMouseOut(this)"></td>    <td width="1"><span class="dropdownbutton" onmouseover="ButtonOver(this)" onmouseout="ButtonOut(this)" onclick="DropDown('+i+')">6</span></td>  </tr></table>';
           
           document.write(str);
           
            str='<table id="ZfSelect'+j+'" class="selectContent" cellspacing=0 cellpadding=0></table>';
           // str='<table id="ZfSelect'+j+'" class="selectContent" cellspacing=0 cellpadding=0>  <tr onmouseover="MouseOver(this)" onclick="MouseClick('+i+',this)" title="作者:Andy">    <td>'+name+'</td>  </tr></table>';
           //alert(str);
           
              document.write(str); 
           ZfSelect[i]=["ZfContainer"+j,name,"ZfSelect"+j] ;
           

           var s=GetObj(ZfSelect[i][0])

           var ZfContainer=GetObj(ZfSelect[i][2])

           ZfContainer.style.width=s.offsetWidth>ZfContainer.offsetWidth?s.offsetWidth:ZfContainer.offsetWidth
          }

          function getSelCount() { 
           var i=1;  
           while (eval("document.getElementById('ZfContainer"+i+"')")!=null) i++;
           return i-1;
           
          }


          function MouseOver(trObj){
           if(!CurrentTR)CurrentTR=trObj
           CurrentTR.className=""
           trObj.className="OnFocus"
                  trObj.title=trObj.innerText
           CurrentTR=trObj;
          }
          //select 選擇框鼠標(biāo)移開時(shí)消失
          function selMouseOut(obj)
          {
           with (document.all.zoom_show)
           {
            style.display = "none"
           }
          }
          function ButtonOver(BtnObj){
           BtnObj.style.backgroundColor='#BAB4A7'
          }
          function ButtonOut(BtnObj){
           BtnObj.style.backgroundColor='#D4D0C8'
          }
          // 使text顯示點(diǎn)擊的值
          // 點(diǎn)擊每一項(xiàng)的時(shí)候調(diào)用的方法
          function piPei(value) {
          for(i=0;i<document.form.persontype.length;i++) {
          var test = document.form.persontype[i].text;
           if(value==test) {
            document.form.realValue.value=document.form.persontype[i].value;
             
          }
          }

          }
          function MouseClick(Index,trObj){ 
           with(GetObj(ZfSelect[Index][1])){
            value=trObj.innerText; //使text顯示點(diǎn)擊的值
            style.backgroundColor='#0A246A';
            style.color='#FFFFFF';
            focus();
            piPei(value);
          for (g=0;g<document.form.persontype.length;g++)
          {
          //alert("enter...");
           if (document.form.persontype.options[g].text==value)
           {
            
            value=value
            break;
           }
          }
           }
           DropDown(Index)
           
          }
          function GoURL(trObj){
           var url=trObj.getAttribute("url")
           if(url&&url!="")window.open(url)
          }

          // 離開輸入框的時(shí)候 失去焦點(diǎn)事件
          function BoxBlur(InputBox){

           with(InputBox.style){backgroundColor="";color=''}
          }

          // 鼠標(biāo)單擊事件 show為true或者false
          // 按下的時(shí)候?yàn)門RUE,
          function DropDown(Index){
           event.cancelBubble=true;
           
           ZfContainerReset(Index);
           var show=GetObj(ZfSelect[Index][2]).style.visibility=='visible';
           
           GetObj(ZfSelect[Index][2]).style.visibility=show?'hidden':'visible';
           setPosition(Index)
          }
          function document::onclick(){
           for(i=0;i<ZfSelect.length;i++){
           GetObj(ZfSelect[i][2]).style.visibility='hidden';
           with(GetObj(ZfSelect[i][2]))for(j=0;j<rows.length;j++)rows[j].style.display="";
          }
          }
          function window::onresize(){
           for(i=0;i<ZfSelect.length;i++)setPosition(i)
          }
          // 鍵盤按下的時(shí)候掉用的事件
          // ZfContainer.rows.length為下拉列表中值的個(gè)數(shù) 這里為8和2
          function showTip(Index){
           var inputbox=GetObj(ZfSelect[Index][1])
           var ZfContainer=GetObj(ZfSelect[Index][2])
           var num=0
           
           ZfContainer.style.visibility="visible"
           for(i=0;i<ZfContainer.rows.length;i++){
            if(ZfContainer.rows[i].cells[0].innerText.indexOf(inputbox.value)!=0)ZfContainer.rows[i].style.display="none"
            else {ZfContainer.rows[i].style.display="";num++}
           }
           if(num==0)ZfContainer.style.visibility='hidden'
          }
          function ZfContainerReset(Index){
           var ZfContainer=GetObj(ZfSelect[Index][2])
           for(i=0;i<ZfContainer.rows.length;i++)
           {
           ZfContainer.rows[i].style.display=""
           
           }
           
           if(CurrentTR)CurrentTR.className=""
          }
          // 公用方法
          function setPosition(Index){
           var s=GetObj(ZfSelect[Index][0])
           var ZfContainer=GetObj(ZfSelect[Index][2])
           var l=s.offsetLeft;
           var t=s.offsetTop;

           while(s=s.offsetParent){l+=s.offsetLeft;t+=s.offsetTop}
           with(ZfContainer.style){left=l+1;top=t+GetObj(ZfSelect[Index][0]).offsetHeight}
          }
          //  得到一個(gè)對(duì)象
          function GetObj(id){

          return document.getElementById(id)


          }

          // 鼠標(biāo)進(jìn)入該區(qū)域的時(shí)候調(diào)用的事件
          // r.text為列表的顯示值

          function selectmove()
          {

           var r
           if(window.event.srcElement.isTextEdit) {
            r=window.event.srcElement.createTextRange();
           }else{
            var el=window.event.srcElement.parentTextEdit;
            //var el=window.event.srcElement.persontype.options[form1.persontype.selectedIndex]
            r=el.createTextRange();
           }
           r.moveToPoint(window.event.x, window.event.y);
           r.expand("word");
           ;
           var str = r.text;
           
           if(str.length > 0 ) {
            with(zoom_show.style) {
             display = "";
             top = event.y + 10;
             left = event.x + 10;
            }
            zoom_show.innerText = str;
           } else {
            zoom_show.style.display = "none";
           }
           
          }

          function bodyclick()
          {
           //alert(name1.value);
          }
          function fuzhi() {
          document.form.realValue.value = document.form.persontype.options[o].value;
          }
          function clickForSubmit()
          {
           var tempValue=document.all["realValue"].value;
           document.location.href="select.html?vaues='"+tempValue+"'";
          }
          </script>
          </head>
          <body onclick="bodyclick()">
          <PRE></PRE>
          <table>
          <form name="form" action="select.html" >

           <div id="zoom_show" style="font-size:12px;color:red;display:none;position:absolute; z-index:2; top:200;background-color: #F7F7F7; layer-background-color: #0099FF; border: 1px #9c9c9c solid;filter:Alpha(style=0,opacity=80,finishOpacity=100);"></div>
          <tr>
           <td><select name="persontype" style="display:none;">
                  <option value='-1'>全部</option>
            <option value='1000'>運(yùn)輸干部運(yùn)輸干部運(yùn)輸干部運(yùn)輸干部運(yùn)輸干部運(yùn)輸干部運(yùn)輸干部</option>
            <option value='1001'>車輛駕駛員</option>
            <option value='1002'>車輛修理工</option>
            <option value='1003'>船艇機(jī)電工</option>
            <option value='1004'>油料員</option>
            <option value='1005'>我自己</option>
           </select></td>
          <tr>


          <script language="javascript">
           addSelect("name1","");
           
            for (g=0;g<document.form.persontype.length;g++)
            {

            addOption(document.form.persontype[g].text,0);
           }

          </script>
          <input type="text">
          <br>
          <select name="persontypssse">
                          <option value='-1'>全部</option>
            <option value='1000'>運(yùn)輸干部運(yùn)輸干部運(yùn)輸干部運(yùn)輸干部運(yùn)輸干部運(yùn)輸干部運(yùn)輸干部</option>
            <option value='1001'>車輛駕駛員</option>
            <option value='1002'>車輛修理工</option>
            <option value='1003'>船艇機(jī)電工</option>
            <option value='1004'>油料員</option>
            <option value='1005'>我自己</option>
           </select>
          <br><br><br><br>
           <input type="hidden" name="realValue" value="">
           <input type="button" value="  點(diǎn)擊提交  " onClick="clickForSubmit();">
          </form>
          </table>
          </body>
          </html>



                  本Blog純屬個(gè)人學(xué)習(xí)、工作需要,記錄相關(guān)資料。請(qǐng)不要發(fā)表任何有人身攻擊的言論,謝謝! www.zhipsoft.cn
          posted on 2007-05-28 15:05 ZhipSoft 閱讀(6436) 評(píng)論(3)  編輯  收藏 所屬分類: JavaScript

          FeedBack:
          # re: 可輸入并可以自動(dòng)檢索的下拉框列表
          2010-01-20 14:30 | ggmm21
          怎樣給select下拉框添加滾動(dòng)條,并支持鍵盤上、下選擇確定  回復(fù)  更多評(píng)論
            
          # dds
          2010-08-18 09:06 | sdfs
          # re: 可輸入并可以自動(dòng)檢索的下拉框列表[未登錄]
          2011-05-26 18:01 | oscar
          同感,我都想知道如何加滾動(dòng)條,這個(gè)非常重要
            回復(fù)  更多評(píng)論
            
          主站蜘蛛池模板: 荔浦县| 都江堰市| 稻城县| 仁寿县| 右玉县| 乌拉特前旗| 沙河市| 龙岩市| 泰来县| 温州市| 大化| 武隆县| 公主岭市| 平顶山市| 郓城县| 原平市| 惠水县| 莲花县| 盐山县| 东阿县| 西乡县| 大石桥市| 公安县| 平利县| 陵川县| 商丘市| 广州市| 贺兰县| 玉屏| 扬中市| 宣恩县| 峨眉山市| 荃湾区| 海原县| 嘉义县| 柞水县| 喜德县| 商丘市| 综艺| 宜州市| 兴宁市|