繁体   English   中英

使Javascript代码在ASP.Net中的DropDownList上的选择更改时触发

[英]Getting Javascript code to fire on a selection change on a DropDownList in ASP.Net

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

所以,这是我的DDL:

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

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

因此,我想得出这样的结论:

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

这可能吗?

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

从代码中添加onchange事件。

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

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

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

观看演示

注意:请确保您为DropDownList使用了正确的ID ,因为server控件倾向于在渲染时更改其ID's

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM