将“onclick”属性添加到asp.net下拉列表项
发布时间:2020-12-16 04:17:54 所属栏目:asp.Net 来源:网络整理
导读:我可以为RadioButtonList项中的项添加属性,如下所示: PaymentMethodDropDownList.Items[0].Attributes.Add("onclick","javascript:showNoMethods();");PaymentMethodDropDownList.Items[1].Attributes.Add("onclick","javascript:showCreditCardMethod();")
我可以为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 – 是存储库单例或静态还是没有这些?
- asp.net – 在asp:按钮上的jQuery Click事件
- 深蓝词库转换1.8发布
- asp.net – 为什么javascript onchange事件不触发
- asp.net-mvc – 如何构建URL路由?
- asp.net – 如何将JsonResult对象作为字符串获取
- asp.net – 全局ASAX中的错误:文件不存在
- asp.net – scriptresource.axd 404错误在asp ne
- asp.net – HTMLEditorExtender在异步回发上编码
- asp.net – Visual Studio的访问修饰符下拉列表选
热点阅读