我现在想实现这样的效果:我选中select中的一个值 text文本会自动变化, 可是select值有很多的话, 该用什么来写呢?for循环 还是switch呢希望高手给写个性能好的办法, 谢谢了

解决方案 »

  1.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>test</title>
    <script>
    function on_change(obj){
    var v = obj.options[obj.selectedIndex].innerText;
    document.getElementById("txt1").value = v;
    }
    </script>
    </head><body>
    <select id="s1" onchange="on_change(this)">
    <option value="1">一</option>
    <option value="2">二</option>
    <option value="3">三</option>
    <option value="4">四</option>
    </select>
    <input type=text id=txt1 value="">
    </body></html>
      

  2.   

    document.getElementById('select1').onchange=function(){
        document.getElementById('txt1').value=this.value;
        /*或者
         switch(this.value)
        {
            case '':
                document.getElementById('txt1').value="...";
                break;
            case '':
                document.getElementById('txt1').value="...";
                break;
        }*/
    }