http://www.51windows.net/hw/asp/jsview.asp?id=318

解决方案 »

  1.   

    select己经有默认的keypress事件,
    就是轮流选择以所输字符打头的选项.
    现在楼主的要求似乎与这个大多数人已经认同的情形相悖!不可以因为某个使用者的想法
    破坏其他更多使用者的习惯
      

  2.   

    不过,
    想输入一个1000-9999的数值
    却采用下框(而不用input)
    真的有点夸张啊!
      

  3.   

    只是举例子说是1000-9999嘛,再说我自己都解决了,默认的keypress事件也可以让它不用嘛,代码如下:<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head>
    <script language="javascript">
    x="";
    str="1111111111";
    function aa()
    { if (event.keyCode==27){
      x="";
      document.f1.s1.options[0].text="";
      f1.s1.options[0].selected=true;
      }
    if (isNaN(parseInt(String.fromCharCode(event.keyCode)))==false){
        if (x.length>=14){
          x=String.fromCharCode(event.keyCode);
      event.returnValue = false;}
        else {
          x=x+String.fromCharCode(event.keyCode);
      event.returnValue = false;}
      }
      if (x.length<=str.length){
        if(x==str.slice(0,x.length)){
           document.f1.s1.options[0].text=x;}}
    else{document.f1.s1.options[0].text=x;}
     x=f1.s1.options[0].text;
    if (x.length==14){
      for (n=1;n<f1.s1.length;n++){
        if (f1.s1.options[n].text==x){
      f1.s1.options[n].selected=true;
      document.f1.s1.options[0].text="";}
      }
    if (f1.s1.options[0].selected==true){
      alert("输入错误!");
      document.f1.s1.options[0].text="";}
    }
    }
    </script>
    <body onLoad="f1.s1.focus();">
    <form name="f1">
    <select name="s1" onkeydown="aa();">
    <option selected></option>
    <script language="javascript">
    for (i=1;i<10;i++){
    document.write("<option>1111111111000"+i+"</option>")}
    for (i=10;i<100;i++){
    document.write("<option>111111111100"+i+"</option>")}
    for (i=100;i<1000;i++){
    document.write("<option>11111111110"+i+"</option>")}
    </script>
    </select>
    </form>
    </body>
    </html>