将“onclick”属性添加到asp.net下拉列表项
发布时间:2020-05-24 13:20:17 所属栏目:asp.Net 来源:互联网
导读:我可以为RadioButtonList项中的项添加属性,如下所示: PaymentMethodDropDownList.Items[0].Attributes.Add(onclick, javascript:showNoMethods(););PaymentMethodDropDownList.Items[1].Attributes.Add(onclick, javascript:
|
我可以为RadioButtonList项中的项添加属性,如下所示: PaymentMethodDropDownList.Items[0].Attributes.Add("onclick","javascript:showNoMethods();");
PaymentMethodDropDownList.Items[1].Attributes.Add("onclick","javascript:showCreditCardMethod();");
PaymentMethodDropDownList.Items[2].Attributes.Add("onclick","javascript:showSendPaymentMethod();");
但是,当我尝试将属性添加到DropDownList控件时,它似乎不起作用.我希望它是相似的. 解决方法这不能以与radioButtonList相同的方式完成,对于下拉列表,正确的属性事件名称是“onchange”而不是“onclick”.该事件应附加到DropDownList本身,而不是如下项目: PaymentMethodDropDownList.Attributes.Add("onchange","showCreditCardMethod();");
此外,这有点复杂,并且需要自定义javascript函数来执行不同的操作,具体取决于所选的选项.这是一个例子: PaymentMethodDropDownList.Attributes.Add("onchange","handleDropDownEvents(this);");
自定义Javascript函数:这假设下拉项的值是“CreditCard”和“SendPayment”. <script type="text/javascript">
function handleDropDownEvents(e){
if(e.value == "CreditCard"){
showCreditCardMethod();
}
else if(e.value == "SendPayment"){
showSendPaymentMethod();
}
}
</script> (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- asp.net – 如何以编程方式触发dropdownlist.sel
- asp.net-mvc – 将属性分配给@ Html.DropdownLis
- asp.net – 有没有比升级到Visual Studio 2010 U
- 如何配置IIS 7以使用子目录作为默认文档?
- Asp.Net 文件操作基类(读取,删除,批量拷贝,删除,
- ASP.NET:global.asax中的Access Session变量
- asp.net-mvc – ASP.Net MVC中的多项目领域3
- asp.net-mvc – ASP.NET MVC 3:RouteExistingFi
- 在asp.net之后的回发动作刷新页面
- ASP.NET:隐藏gridview中的列
热点阅读
