• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    DropDownList添加客户端下拉事件操作

    如果要想给 DropDownList 服务器控件添加客户端下拉事件,我们可以强制给它添加 onchange 事件,尽管在控件中没有这个方法的提示。添加完这个事件还不能达到目的,还要设置 AutoPostBack 属性为 false,不让它回发后台事件。
    以下就是为大家分享的代码:

    html xmlns="http://www.w3.org/1999/xhtml" >
    head runat="server">
      title>DropDownList添加客户端下拉事件/title>
      script type="text/javascript">
        function getDropDownList() {
          var ddl1 = document.getElementById("%=ddl1.ClientID%>");
          var text = ddl1.options[ddl1.options.selectedIndex].text; //获取text值
          var value = ddl1.value;                  //获取value值
          alert("Text:" + ddl1.options[ddl1.options.selectedIndex].text + ", Value:" + ddl1.value); 
        }
      /script>
    /head>
    body>
    form id="form1" runat="server">
      asp:DropDownList ID="ddl1" runat="server" AutoPostBack="false" onchange="getDropDownList();">
        asp:ListItem Text="T1" Value="V1" Selected="True">/asp:ListItem>
        asp:ListItem Text="T2" Value="V2">/asp:ListItem>
        asp:ListItem Text="T3" Value="V3">/asp:ListItem>
      /asp:DropDownList>
    /form>
    /body>
    /html>

    总结一下,也就是说,要想给DropDownList下拉框添加客户端下拉事件,必须做两步工作,一是添加强制onchange事件,二是把 AutoPostBack属性设为false,就是这么简单!

    您可能感兴趣的文章:
    • 在dropDownList中实现既能输入一个新值又能实现下拉选的代码
    • DropDownList 下拉框选择改变促发事件和防全局刷新(推荐)
    • DropDownList绑定选择数据报错提示异常解决方案
    • 用javascript为DropDownList控件下拉式选择添加一个Item至定义索引位置
    • asp.net中不能在DropDownList中选择多个项 原因分析及解决方法
    • ASP.NET中DropDownList下拉框列表控件绑定数据的4种方法
    • C#使用DropDownList绑定添加新数据的方法汇总
    • asp.net DropDownList实现二级联动效果
    • DropDownList实现可输入可选择(两种版本可选)
    上一篇:DropDownList设置客户端事件思路
    下一篇:ASP.NET实现用户注册和验证功能(第4节)
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    DropDownList添加客户端下拉事件操作 DropDownList,添加,客户端,