当前位置:主页 > 网页前端 > JavaScript代码 >

JS获取DropDownList的value值与text值的示例代码

时间:2021-05-11 08:51:37 | 栏目:JavaScript代码 | 点击:

相关JS:
复制代码 代码如下:

<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>

调用:
复制代码 代码如下:

<asp:DropDownList ID="DropDownList1" runat="server" onchange="SearchChange();">
    <asp:ListItem Value="0">111</asp:ListItem>
    <asp:ListItem Value="1">222</asp:ListItem>
    <asp:ListItem Value="2">333</asp:ListItem>
</asp:DropDownList

您可能感兴趣的文章:

相关文章