<select id='LayerList' onchange='ShowFieldInfo()'><option value="0">cam_bnd</option><option value="1">canada</option><option value="2">mexico</option><option value="3">States</option>用document.getElementById("LayerList").value得到的是1,2。
但我想得到的是选中选项中的值:比如cam_bnd,canada。

解决方案 »

  1.   


    <script language="javascript">
        function ShowFieldInfo(obj){
        alert(obj.options[obj.selectedIndex].text)
        }
        
    </script><body>
    <select id='LayerList' onchange='ShowFieldInfo(this)' NAME="LayerList"><option value="0">cam_bnd</option><option value="1">canada</option><option value="2">mexico</option><option value="3">States</option></body>
      

  2.   


    var obj=document.getElementById("LayerList");
    alert(obj.options[obj.selectedIndex].value);
      

  3.   


    <html>
    <head>
    <script type="text/javascript">
    function ShowFieldInfo()
    {
    var sel=document.getElementById("LayerList");
    alert(sel.options[sel.options.selectedIndex].text);
    }
    </script>
    </head>
    <body>
    <select id='LayerList' onchange='ShowFieldInfo()'>
    <option value="0">cam_bnd</option>
    <option value="1">canada</option>
    <option value="2">mexico</option>
    <option value="3">States</option>
    </body>
    </html>
    测试通过的