function chgselectlist()
{
var txt = document.all.item("strtest").value // 输入文字
    var txtlength = txt.length for(var i=0; i<document.all.item("comm").length; i++)
{
if(document.all.item("comm").options[i].text.substring(0, txtlength) == txt)
{
document.all.item("comm").options[i].selected = true
return
}
}}

解决方案 »

  1.   


    谢谢楼上,可是还是没有实现我要的效果,我是要根据input里的文字,来把select的文本里凡是含有input里字符串的选项都排在靠前的位置,好方便用户选择。奇遇不含有相应字符串的选项,则排在靠后的位置,
    仍然要提供给用户选择的。  
      

  2.   

    <script>
    function chgselectlist()
    {
    var txt = document.all.item("strtest").value // 输入文字
    var txtlength = txt.length;
    obj = document.all.item("comm");
    for(var i=0; i<obj.length; i++) {
    if(obj.options[i].text.substr(0,txtlength) == txt) {
    j = i;
    while(j>1 && obj.options[j-1].text.substr(0,txtlength) != txt) {
    obj.options[j].swapNode(obj.options[j-1]);
    j--;
    }
    }
    }
    }
    </script>
      

  3.   

    <script>
    function chgselectlist()
    {
    var tmp=strtest.value,j=0
    for(var i=0;i<comm.length;i++)
    {
    if(eval("comm["+i+"].text.search(/"+tmp+"/)!=-1"))
    {
    var j=0
    comm[i].swapNode(comm[j])
    j++
    }
    }
    }
    </script>
      

  4.   

    <script>
    function chgselectlist()
    {
    var tmp=strtest.value,j=0
    var j=0
    for(var i=0;i<comm.length;i++)
    {
    if(eval("comm["+i+"].text.search(/"+tmp+"/)!=-1"))
    {
    comm[i].swapNode(comm[j])
    j++
    }
    }
    }
    </script>
      

  5.   

    我只测试了sw47(小豆冰棍儿) 是可以用的,没有测试xuzuning(唠叨) 的,但我想也应该是可以的,而且我现在采用了sw47(小豆冰棍儿) 写的函数。谢谢大家的帮忙。