【问题标题】:Getting Javascript code to fire on a selection change on a DropDownList in ASP.Net让 Javascript 代码触发 ASP.Net 中 DropDownList 上的选择更改
【发布时间】:2012-09-28 10:32:14
【问题描述】:

我想添加 Javascript 代码,以便在 asp.net 的下拉列表中更改所选索引时触发。

所以,这是我的 DDL:

<asp:DropDownList ID="comboReportTypes" runat="server" />

我想在上面的 DDL 中添加类似这样的内容:onSelectionIndexChanged="MyJavascriptFuntion(this)"

所以我想以这样的方式结束:

<asp:DropDownList ID="comboReportTypes" runat="server" onSelectionIndexChanged="MyJavascriptFuntion(this)" />

这可能吗?

提前致谢。我正在使用 ASP.Net 4.0

【问题讨论】:

    标签: javascript selectedindexchanged


    【解决方案1】:

    从代码中添加 onchange 事件。

    例如: DropDownList dlOption = new DropDownList(); dlOption.Attributes.Add("onchange", "javascript:return functionname(this);");

    【讨论】:

      【解决方案2】:

      使用jquery,您可以轻松实现您想要做的事情

      $('#comboReportTypes').change(function(){
      //do whatever you need to.
      });
      

      See Demo

      注意:确保为DropDownList 使用正确的ID,因为server 控件往往会在呈现时更改其ID's。

      【讨论】:

        猜你喜欢
        • 2015-09-19
        • 1970-01-01
        • 1970-01-01
        • 2019-04-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-11-29
        • 1970-01-01
        相关资源
        最近更新 更多