-1; var isIE = navigator.userAgent.ind ;更新日期:2026/1/18.幽灵资源网,磁力链接,云盘下载,BT种子,CPU天梯,显卡天梯,UU加速器,阅读3.0,英雄联盟,怪物猎人,无损音乐网,无损音乐下载网站,无损音乐免费下载,320Kmp3下载,无损音乐免费下载网站,音画欣赏,无损音乐,抖音神曲,发烧大碟,车载歌曲,试音天碟,WMA,WAV+CUE,WAV整轨,FLAC分轨,DSD黑胶,HI-FI试音,SACD-ISO,4K高清,高清电影下载,Magnet,Torrent,BitTorrent,迅雷快传,SUB,SRT,ASS/SSA,SUP,RARBG,TLF字幕,BluRay,x265,x264,DTS-HD,WEBRip,10BIT,HDR,DDP5.1,WEB-DL,1080p高清电影下载,中国高清网,高清电影,720p,1080p,MKV,AVI,蓝光原盘,3D高清,电影下载">

Autocomplete Textbox Example javascript实现自动完成成功

网络编程 发布日期:2026/1/18 浏览次数:1

正在浏览:Autocomplete Textbox Example javascript实现自动完成成功

复制代码 代码如下:
<SCRIPT language=JScript type=text/javascript> 
var isOpera = navigator.userAgent.indexOf("Opera") > -1; 
var isIE = navigator.userAgent.indexOf("MSIE") > 1 && !isOpera; 
var isMoz = navigator.userAgent.indexOf("Mozilla/5.") == 0 && !isOpera; 
function textboxSelect (oTextbox, iStart, iEnd) { 
   switch(arguments.length) { 
       case 1: 
           oTextbox.select(); 
           break; 
       case 2: 
           iEnd = oTextbox.value.length; 
           /* falls through */ 

       case 3:          
           if (isIE) { 
               var oRange = oTextbox.createTextRange(); 
               oRange.moveStart("character", iStart); 
               oRange.moveEnd("character", -oTextbox.value.length + iEnd);      
               oRange.select();                                              
           } else if (isMoz){ 
               oTextbox.setSelectionRange(iStart, iEnd); 
           }                     
   } 
   oTextbox.focus(); 

/*
function textboxReplaceSelect (oTextbox, sText) { 
   if (isIE) { 
       var oRange = oTextbox.createTextRange(); 
       oRange.text = sText; 
       oRange.collapse(true); 
       oRange.select();                                 
   } else if (isMoz) { 
       var iStart = oTextbox.selectionStart; 
       oTextbox.value = oTextbox.value.substring(0, iStart) + sText + oTextbox.value.substring(oTextbox.selectionEnd, oTextbox.value.length); 
       oTextbox.setSelectionRange(iStart + sText.length, iStart + sText.length); 
   } 
   oTextbox.focus(); 

*/
function autocompleteMatch (sText, arrValues) { 
   for (var i=0; i < arrValues.length; i++) { 
       if (arrValues[i].indexOf(sText) == 0) { 
           return arrValues[i]; 
       } 
   } 
   return null; 

function autocomplete(oTextbox, oEvent, arrValues) { 
   switch (oEvent.keyCode) { 
       case 38: //up arrow  
       case 40: //down arrow 
       case 37: //left arrow 
       case 39: //right arrow 
       case 33: //page up  
       case 34: //page down  
       case 36: //home  
       case 35: //end                  
       case 13: //enter  
       case 9: //tab  
       case 27: //esc  
       case 16: //shift  
       case 17: //ctrl  
       case 18: //alt  
       case 20: //caps lock 
       case 8: //backspace  
       case 46: //delete 
           return true; 
           break; 
       default: 
     // 下面这一行用处不大(被注释)
           //textboxReplaceSelect(oTextbox, isIE ? oTextbox.value/*oEvent.keyCode*/ : oEvent.charCode); 
           var iLen = oTextbox.value.length; 
           var sMatch = autocompleteMatch(oTextbox.value, arrValues); 
           if (sMatch != null) { 
               oTextbox.value = sMatch; 
               textboxSelect(oTextbox, iLen, oTextbox.value.length); 
           }  

           return false; 
   } 

       </SCRIPT>
<SCRIPT> 
               var arrValues = ["red", "orange", "yellow", "green", "blue", "indigo", "violet", "brown"]; 
       </SCRIPT>
<H2>Autocomplete Textbox Example</H2>
<P>Type in a color in lowercase:输入一个以小写字母开头的颜色(英文单词,比如:r、 b等)<BR><INPUT id=txt1 onkeyup="return autocomplete(this, event, arrValues)"></P>