我想问这个红色部分是怎么实现的。 
------------------------------------------------------------select能实现吗? 模拟select吧

解决方案 »

  1.   

    直接设置document.getElementById("font1").value=str试试
      

  2.   


    <input type="text" onkeyup="fSelect(this.value)" />
    <select name="font1" id="font1" style="width:100px">
    <option value="Arial">Arial</option>
    <option value="宋体">宋体</option>
    <option value="黑体">黑体</option>
    </select>
    <script type="text/javascript">
    <!--
    function fSelect(str){
    var Obj=document.getElementById("font1")
    for(var i=0;i<Obj.length;i++){
    if(Obj[i].value==str){
    Obj.selectedIndex=i;
    }
    }
    }
    -->
    </script>实在是不明白你在说什么……
      

  3.   

    stayalive你好,很感谢你回我的帖子,我的意思是如果你的那个程序里面的“str”这个参数是“楷体”的话,我想把这个“楷体”也显示在select框上。但是前提是不把这个“楷体”作为select框的一项加进来,而是要保持select项不变。也就是select只显示这个新值。
      

  4.   

    明白你的意思﹐好像要自己用div模擬select
      

  5.   

    <input type="text" onchange="fSelect(this.value)" />
    <select name="font1" id="font1" style="width:100px">
    <option value="Arial">Arial</option>
    <option value="宋体">宋体</option>
    <option value="黑体">黑体</option>
    </select>
    <script type="text/javascript">
    <!--
    function fSelect(str){
        var Obj=document.getElementById("font1")
        for(var i=0;i<Obj.length;i++){
            if(Obj[i].value==str){
                Obj.selectedIndex=i;
                return;
            }
        }  var option_node = document.createElement("OPTION");     
      option_node.text=str;  
      font1.add(option_node); 
    }
    -->
    </script>