<ptml> <pead> <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "> <meta content=" Fason, a letter "name=author> <title> dynamic drop-down box </title> <style> a{ COLOR:RED;TEXT-DECORATION:NONE;FONT-SIZE:12PX} </style> </pead> <body onload= "Init ()" > <center > <p> dynamic hint drop-down box </p> <pr> <form name=frm> <table> <tr> <td> Please enter 1 or 2 or 3 or 4 or 5 test: <input name= "txt" onkeyup= "selecttip (0)" > <input type= "button" value= "reset" onclick= "Selecttip (1 ) "></td> </tr> <tr> <td> <span id=" demo "><select name=" Demo "size=10 Onchange= "Txt.value=options[selectedindex].text;" > <option value= "1" >1</option> <option value= ">12</option> <option value=" 123 ">123</option> <option value=" 1234 ">1234</option> <option value=" 2 ">2</OPTION&G T <option ValUe= "<option" >23</option> value= "234" >234</option> <option value= "2345" >2345</op Tion> <option value= "3" >3</option> <option value= ">34</option> <option val" Ue= "345" >345</option> <option value= "3456" >3456</option> <option value= "5" >5</opti on> <option value= "Wuyi" >51</option> <option value= "51w" >51w</option> <option V Alue= "51wi" >51wi</option> <option value= "51win" >51win</option> <option value= "51windows" >51windows</option> </select></span> </td> </tr> </form> </table > <pr> <script language= "JavaScript" > var temparr=[];//storage option Function Init () {var selectobj=docume Nt.frm.elements["Demo"]/* First put the data into the array/with (Selectobj) for (i=0;i<length;i++) temparr[i]=[options[i].text,options[ I].value]} function SeLecttip (flag) {var txtobj=document.frm.elements["txt"] var Selectobj=document.getelementbyid ("demo") var arr=[] with ( Selectobj) {var selecthtml=innerhtml.match (/<[^>]*>/) [0] for (i=0;i<temparr.length;i++) if (TempA Rr[i][0].indexof (txtobj.value) ==0| | Flag)//if found with the content of txt beginning, add option. If flag is true, initialize the dropdown box arr[arr.length]= "<option value=" +temparr[i][1]+ "' >" +temparr[i][0]+ "</option>" in Nerhtml=selecthtml+arr.join () + "</SELECT>"}} </script> </body>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]