posts - 42,  comments - 84,  trackbacks - 0
          原來在某個網站發現過一個很好用的可編輯下拉,這兩天因為需要使用再次的去找那個.卻怎么也找不到了,在一番baidu,google終于還是沒有找到.但是無心插柳,發現了一個更加不錯的,所以貼出來.同時為了保持下拉不被影響,可以將原來的輸入提示下拉去掉,代碼為autocomplete="off" 
          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
          <html>
          <title>可編輯下拉</title>
          <head>
          <meta name="keywords" content="51windows.Net">
          <meta http-equiv=Content-Type content="text/html; charset=gb2312">
          <style>
          .sdiv
          {font-size:12px;overflow-y:auto;overflow-x:hidden;height:expression(this.parentElement.style.pixelHeight);z-index:101;}
          .sdivover
          {background:highlight;color:highlighttext;width:100%;padding-left:3px;cursor:default;overflow:hidden;hidden;line-height:120%;}
          .sdivout 
          {background:#FFFFFF;color:#000000;width:100%;padding-left:3px;cursor:default;overflow:hidden;line-height:120%;}
          input
          {haiwa:expression(this.onkeyup=__ACP);hw:expression(this.ondblclick=__ACP);}
          </style>
          </head>
          <body onclick="divclick()" onkeydown="KeyDown()">
          <SCRIPT LANGUAGE="JavaScript">
          <!--
          var __InputName;
          var HighLine = 0
          var MenuStrs = ""
          var MenuLines = 0
          var KeyOnMenu = false
          var _AutoObj
          var ShowLine = 10
          var LineHeight = 15
          var SelectValue = "";
          var __InputName;
          function DivOver(obj){
              
          if (KeyOnMenu){
                  updateHtml(
          -1);
                  KeyOnMenu 
          = false
              }

              obj.className
          ="sdivover";
          }


          function divclick(obj){
              document.getElementById(
          "__AutocompleteDiv").style.display = "none";
              
          if (obj){
                  selectedvalue 
          = obj.innerText;
                  __InputName.value 
          = selectedvalue;
              }

              HighLine 
          = 0
              _Autostr 
          = ""
              SelectValue 
          = ""
          }

          function __ACP(){
              
          if (event.keyCode!=13){
                  event.cancelBubble
          =true
                  e 
          = this;
                  
          var t=e.offsetTop; 
                  
          var l=e.offsetLeft; 
                  
          var w=e.offsetWidth;
                  
          var h=e.offsetHeight;
                  _AutoObj 
          = this
                  divID 
          = document.getElementById("__AutocompleteDiv");
                  __InputName 
          = this;
                  updateHtml(HighLine);
                  
          if (MenuLines>0){
                      
          while(e=e.offsetParent)
                      

                          t
          +=e.offsetTop; 
                          l
          +=e.offsetLeft; 
                      }

                      divID 
          = eval(divID);
                      divID.style.top 
          = t+h;
                      divID.style.left 
          = l;
                      divID.style.width 
          = w;
                      divID.style.height 
          = MenuLines * LineHeight>ShowLine*LineHeight?ShowLine*LineHeight:MenuLines * LineHeight;
                      divID.style.display 
          = ""
                  }

                  
          else{
                      divID.style.display 
          = "none"
                  }

              }

          }

          function InsertSort(arr) //插入排序->直接插入法排序@panliu888
              var temp, j;
              
          for(var i=1; i<arr.length; i++{
                  
          if((arr[i]) < (arr[i-1])) {
                      temp 
          = arr[i];
                      j 
          = i-1;
                      
          do {
                          arr[j
          +1= arr[j];
                          j
          --;
                      }

                      
          while (j>-1 && (temp) < (arr[j]));
                      arr[j
          +1= temp;
                  }
          //endif
              }

              
          return arr;
          }

          function updateHtml(k){
               listhtml 
          = ""
              
          var line = 0
              htmlarr 
          = InsertSort(_AutoObj.autolist.split("|"))
              
          var liststrarr = htmlarr;
              
          for(i=0;i<liststrarr.length;i++){
                  
          if((liststrarr[i].substr(0,_AutoObj.value.length)==_AutoObj.value)&&(liststrarr[i].length>_AutoObj.value.length)){
                      line 
          ++;
                      
          if (k==line){
                          SelectValue 
          = liststrarr[i]
                          listhtml 
          += '<div class="sdivover" onclick="divclick(this)" onmouseover=DivOver(this);HighLine='+line+';SelectValue="'+liststrarr[i].replace(/\"/ig,"\\"")+'"; onmouseout=this.className="sdivout";>'+liststrarr[i]+'</div>';
                      }

                      
          else
                          listhtml 
          += '<div class="sdivout" onclick="divclick(this)" onmouseover=DivOver(this);HighLine='+line+';;SelectValue="'+liststrarr[i].replace(/\"/ig,"\\"")+'"; onmouseout=this.className="sdivout";>'+liststrarr[i]+'</div>';
                  }
              }
              MenuLines = line
              document.getElementById(
          "__AutocompleteDivlist").innerHTML = listhtml;
              document.getElementById(
          "__AutocompleteDivlist").scrollTop = (k-ShowLine)>0?(k-ShowLine)*LineHeight:0;
          }
          function KeyDown(){
              switch ( event.keyCode ){
                  case 13 : if(SelectValue.length>0){_AutoObj.value =SelectValue;divclick();}break ;
                  case 38 : KeyMove(-1) ;    break ;
                  case 40 : KeyMove(1) ;    break ;
              }
          }
          function KeyMove(n){
              HighLine = HighLine+(n);
              if (parseInt(HighLine)>parseInt(MenuLines)){HighLine = 1;}
              if(parseInt(HighLine)<1){HighLine = MenuLines;}
              KeyOnMenu = true;
              updateHtml(HighLine)
          }
          //-->
          </SCRIPT>
          昵稱:<input type=
          "text" autolist="A|B|C|D" size="40" name="q"><br>
          網址:<input type=
          "text" autolist="A|B">
          <div id=
          "__AutocompleteDiv" style="position: absolute;border: 1 solid #000000;display:none;height:180px;background:#FFFFFF;" onClick="event.cancelBubble=true">
          <div class=
          "sdiv" id="__AutocompleteDivlist" onClick="event.cancelBubble=true">
          </div>
          </div>
          </body>
          </html>
          posted on 2007-07-16 10:09 Dong 閱讀(406) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 东莞市| 舞阳县| 麻江县| 桐柏县| 泾川县| 永济市| 阿拉善左旗| 德安县| 成武县| 安泽县| 额尔古纳市| 龙游县| 扎兰屯市| 托克逊县| 思茅市| 天津市| 岑溪市| 城步| 德钦县| 赤城县| 通城县| 墨竹工卡县| 靖安县| 潢川县| 荔浦县| 西安市| 剑川县| 霍城县| 比如县| 潼南县| 白玉县| 蓝山县| 孝感市| 东山县| 余干县| 任丘市| 灵山县| 嘉兴市| 永年县| 凤翔县| 龙南县|