var pattern = /6/;
遍历所有option 看是否匹配

解决方案 »

  1.   

    能不能具体点,写下code,谢谢
      

  2.   


    translate(val)
    {
      var test = document.getElementById("test"); //select要加id属性
      for(var i=0;i<test.options.length;i++)
      {
        if(test.options[i].text.indexOf("6") == -1) {test.options.remove(i);}
      }
    }
      

  3.   


    可把"6"换成val
      

  4.   

    代码经过测试
    <script type="text/javascript">
    function FindOption( oText )
    {
      var array = new Array("1111","11123","322213","45664","456699","777888");
      var oSelect = document.getElementById("select1");
      oSelect.options.length = 1;
      for(var i=0; i < array.length; i++)
      {
        var pattern = new RegExp(oText.value);
        if(pattern.test(array[i]))
        {
          var option=new Option(array[i],i);
          oSelect.options.add(option);
        }
      }
    }
    </script>
    <input type="text" id="text1" onpropertychange="FindOption(this)">
    <select id="select1" style="width:150px">
    <option value=""></option>
    </select>
      

  5.   

    我用了的code,输入6出来是1111/322213/456699,不符合要求呢,不知道test.options[i].text.indexOf("6")   ==   -1是什么意思?请教“我本有心”
      

  6.   


    translate(val) 

        var   test   =   document.getElementById("test");   //select要加id属性 
        for(var   i=0;i <test.options.length;i++) 
        { 
            if(test.options[i].text.indexOf("6")   ==   -1)   {test.options.remove(i);} 
        } 
    } test.options[i].text.indexOf("6")       ==       -1 说明option的文本不含有字串6
    这样写应该是OK的吧?