<input ... autocomplete="yes"/>

解决方案 »

  1.   

    看看这个(别人的程序) 有些帮助
    <HTML><HEAD>
    <TITLE>Webdiyer制造:)(http://www.webdiyer.com)</TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="Webdiyer">
    <SCRIPT LANGUAGE="JavaScript">
    <!--//window.showModalDialog('11.htm','','dialogWidth=50;dialogTop=10;dialogLeft=50;center:no;help:no;')var dom=document.all;function SetSize(){
    dom.sel.style.width=dom.sel.parentElement.offsetWidth;
    //alert(dom.sel.style.width);
    dom.itxt.style.width=dom.itxt.parentElement.offsetWidth-20;
    dom.sel.style.position="absolute";
    dom.sel.style.top=dom.sel.parentElement.offsetTop+1;
    dom.sel.style.left=dom.sel.parentElement.offsetLeft;
    dom.sel.style.clip="rect(auto auto auto "+(dom.sel.clientWidth-20)+")";
    //alert(dom.sel.style.clip);
    }function ChangeIndex(){
    dom.itxt.value=dom.sel.options[dom.sel.selectedIndex].text;
    }var l;//文本框中文字的长度
    function BoxKeyDown(){
    l=dom.itxt.value.length;
    }function BoxKeyUp(){
    var el=dom.sel;
    var tl=dom.itxt.value.length;
    var kcode=event.keyCode;
    if(!(kcode==8||kcode==9||kcode==16||kcode==17||kcode==35||kcode==37||kcode==39||kcode==46)){
    if(tl!=l){
    for(i=0;i<el.options.length;i++){
    if(el.options[i].text.substring(0,tl).toLowerCase()==dom.itxt.value.toLowerCase()){
    dom.itxt.value=el.options[i].text;
    var txtRange=dom.itxt.createTextRange();
    txtRange.moveStart("character",tl);
    txtRange.select();
    break;
    }
    }
    }
    }
    }
    //-->
    </SCRIPT>
    </HEAD><BODY onload="SetSize()">
    <span id="sp" style="width:15%">
    <input type="text" id="itxt" onfocus="this.select()" onkeydown="BoxKeyDown()" onkeyup="BoxKeyUp()"><br>
    <select id="sel" onchange="ChangeIndex()">
    <option>hello,world!
    <option>你从哪里来
    <option>中华人民共和国
    <option>陕西省吴旗县
    <option>西安市政府
    <option>大abc世界
    <option>1hello,world!
    <option>2你从哪里来
    <option>3中华人民共和国
    <option>4陕西省吴旗县
    <option>5西安市政府
    <option>6大abc世界
    <option>7hello,world!
    <option>8你从哪里来
    <option>9中华人民共和国
    <option>10陕西省吴旗县
    <option>11hello,world!
    <option>12你从哪里来
    <option>13中华人民共和国
    <option>14陕西省吴旗县
    <option>15西安市政府
    <option>16大abc世界
    <option>17hello,world!
    <option>18你从哪里来
    <option>19中华人民共和国
    <option>20陕西省吴旗县
    <option>21hello,world!
    <option>22你从哪里来
    <option>23中华人民共和国
    <option>24陕西省吴旗县
    <option>25西安市政府
    <option>26大abc世界
    <option>27hello,world!
    <option>28你从哪里来
    <option>29中华人民共和国
    <option>30陕西省吴旗县
    <option>41hello,world!
    <option>42你从哪里来
    <option>43中华人民共和国
    <option>44陕西省吴旗县
    <option>45西安市政府
    <option>46大abc世界
    <option>47hello,world!
    <option>48你从哪里来
    <option>49中华人民共和国
    <option>50陕西省吴旗县
    <option>61hello,world!
    <option>62你从哪里来
    <option>63中华人民共和国
    <option>64陕西省吴旗县
    <option>65西安市政府
    <option>66大abc世界
    <option>67hello,world!
    <option>68你从哪里来
    <option>69中华人民共和国
    <option>70陕西省吴旗县
    <option>81hello,world!
    <option>82你从哪里来
    <option>83中华人民共和国
    <option>84陕西省吴旗县
    <option>85西安市政府
    <option>86大abc世界
    <option>87hello,world!
    <option>88你从哪里来
    <option>89中华人民共和国
    <option>90陕西省吴旗县
    <option>100hello,world!
    </select>
    </span>
    </BODY></HTML>
      

  2.   

    <script>
    function match(oTxt){
    var length = sel.options.length;
    while (length--)
    {
        if (sel.options[length].value.indexOf(oTxt.value) >= 0)
    {
    sel.selectedIndex = length;
    break;
    }
    }
    }
    </script>
    <input type=text autocomplete="yes" onkeyup="match(this)">
    <br>
    <select id="sel" multiple>
    <option value="adfs1">adfa1</option>
    <option value="a2">a2</option>
    <option value="a3">a3</option>
    <option value="a4">a4</option>
    <option value="b1">b1</option>
    <option value="b2">b2</option>
    <option value="b3">a3</option>
    <option value="d1">d1</option>
    <option value="d2">d2</option>
    <option value="d3">d3</option>
    </select>
      

  3.   

    更正一下,可能查的结果仍不太准确:
    ---------------<script>
    function match(oTxt){
    var length = sel.options.length;
    for ( i = 0; i < length; i++ )
    {
    alert(sel.options[i].value);
        if (sel.options[i].value.indexOf(oTxt.value) >= 0)
    {
    sel.selectedIndex = i;
    break;
    }
    }
    }
    </script>
    <input id=txt type=text autocomplete="yes" onkeyup="match(this)">
    <br>
    <select id="sel" multiple onclick="txt.value=this.value">
    <option value="adfs1">adfa1</option>
    <option value="a2">a2adf</option>
    <option value="a3">a3afds</option>
    <option value="ba4">ba4</option>
    <option value="b1">b1</option>
    <option value="b2">b2</option>
    <option value="b3">a3</option>
    <option value="d1">d1</option>
    <option value="d2">d2</option>
    <option value="d3">d3</option>
    </select>