用JS获取DropDownList选中得值

HTML:

 

 <td style="width: 20%">
    <asp:DropDownList ID="DropdownList1" runat="server" AutoPostBack="true" />
 </td>

 <input type="button" id="btnSubmit" name="btnSubmit" value="保存"  onclick="getvalue();"/>

JS:

    <script type="text/javascript">

function getvalue(){

                var select1 = document.all.<%= DropdownList1.ClientID %>;
                var selectvalue = select1.options[select1.selectedIndex].value;
                var selectText= select1.options[select1.selectedIndex].text;

               alert(selectvalue+"  "+selectText);

}

    </script>

其他网上给出的:

    <script type="text/javascript" language="javascript">
    function SearchChange()
    {
        var ddl = document.getElementById("DropDownList1")  
        var index = ddl.selectedIndex;  
           
        var Value = ddl.options[index].value;  
        var Text = ddl.options[index].text;
       
        alert(Value);
    }
    </script>

方式获取的ddl 为null;

你可能感兴趣的:(JavaScript,html,server,function,asp,button)