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