启用和禁用控件 [英] Enable and Disalble Controls
本文介绍了启用和禁用控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我使用的是Asp.net C#,我有一个下拉列表,其中填充了数据库中的数据,例如A,B,C,D >
现在我有一个radiobutton,我想要的是当我从DropDownlist中点击A或D时RadioButton得到启用,当我点击B或c radiobutton获取禁用时。
请帮助
Hello,
I am using Asp.net C# , I have one dropdownlist filled with data from database for example A,B,C,D
now i have one radiobutton , what i want is when i click A or D from DropDownlist RadioButton get enable , and when i click B or c radiobutton Get Disable.
please help
推荐答案
Hi
假设A,B,C,D是DropDown DataTextField值,你可以使用这个逻辑。
Hi Assuming that A,B,C,D are DropDown DataTextField Values, You can use this logic.
function DisableRadioButton(obj) {
var currentDropDownText = obj.options[obj.selectedIndex].text;
if(currentDropDownText =="A" || currentDropDownText =="D")
{
(' #<%= radioId.ClientID%>') .attr(' disabled', false );
}
< / pre >
('#<%=radioId.ClientID%>').attr('disabled', false); } </pre>
您是否尝试过使用javascript ?
Hi,
Did you try doing that using javascript ?
function disableControl(){
if(document.getElementById('dropdownID').value=="A")
{
document.getElementById('radioButtonID').disabled=true;
}
else
{
document.getElementById('radioButtonID').disabled=false;
}
}
我还没有测试过这段代码。但这可以给你一个想法。
另外,检查下拉列表的默认选择值。
问候,
Praneet
I havent tested this code. But this can give you an idea.
Also, check what will be the default selected value for the dropdown.
Regards,
Praneet
这篇关于启用和禁用控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文