加入收藏 | 设为首页 | 会员中心 | 我要投稿 聊城站长网 (https://www.0635zz.com/)- 智能语音交互、行业智能、AI应用、云计算、5G!
当前位置: 首页 > 教程 > 正文

展示如何使用JS从DropdownList中提取价值和文本的示例代码

发布时间:2023-09-14 15:09:28 所属栏目:教程 来源:
导读:相关JS:

代码如下:

<script type="text/javascript" language="javascript">

function SearchChange()

{

var ddl = document.getElementById("DropDownList1")

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

(编辑:聊城站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章