Ajax问题(如何选中单选按钮即时改变下拉列表框的属性?)

LutzMark 2007-05-24 03:36:47
页面有一个组RadioButto(假设是 a,b,c)和一个DropDownList,页面首次加载时DropDownList的Enabled属性为false,当选中RadioButton b 时DropDownList的Enabled属性即时改为ture,要求不刷新页面。这该如何实现?没接触过Ajax,请高手赐教!
...全文
274 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
LutzMark 2007-05-24
  • 打赏
  • 举报
回复
实在不好意思,一激动分都给慕白兄了。给过了还不能修改 :(
LutzMark 2007-05-24
  • 打赏
  • 举报
回复

按照慕白兄和紫色阴影的思路,综合了一下。功能已实现,代码如下:
前台:
<asp:RadioButton ID= "RadioButton1" GroupName= "a" runat= "server" />
<asp:RadioButton ID= "RadioButton2" GroupName= "a"
runat="server" />
<asp:RadioButton ID= "RadioButton3" GroupName= "a" runat= "server"/>

<asp:DropDownList ID= "DropDownList1 " runat= "server " Enabled= "False">

后台:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RadioButton1.Attributes.Add("onclick", "document.getElementById('DropDownList1').disabled = true");
RadioButton2.Attributes.Add("onclick", "document.getElementById('DropDownList1').disabled = false");
RadioButton3.Attributes.Add("onclick", "document.getElementById('DropDownList1').disabled = true");
}
babyrockxray 2007-05-24
  • 打赏
  • 举报
回复
cpp兄的写法比较简洁清楚一点 :)
yudi010 2007-05-24
  • 打赏
  • 举报
回复
搂住不给 babyrockxray(紫色阴影) 分数 感觉有点不可思议
yudi010 2007-05-24
  • 打赏
  • 举报
回复
用js就可以实现
page load里面:
RadioButton1.Attributes.Add("onclick", "test('RadioButton2')");
RadioButton2.Attributes.Add("onclick", "test('RadioButton2')");
RadioButton3.Attributes.Add("onclick", "test('RadioButton2')");

aspx:
function test(id)
{
if(document.getElementById(id).checked)
{
document.getElementById('DropDownList1').disabled = false;
}
}

可以实现 后台邦定了事件代码,前台调用 babyrockxray(紫色阴影) 答案ok
LutzMark 2007-05-24
  • 打赏
  • 举报
回复
问题已解决!原来是个很简单的问题啊哈 谢谢楼上两位。
net_lhb 2007-05-24
  • 打赏
  • 举报
回复
jf
yudi010 2007-05-24
  • 打赏
  • 举报
回复
不刷新页面
试一试去 学习
cpp2017 2007-05-24
  • 打赏
  • 举报
回复
<asp:RadioButton ID="RadioButton1" onclick="document.getElementById('DropDownList1').disabled = true" runat="server" GroupName="a" /> <asp:RadioButton ID="RadioButton2" onclick="document.getElementById('DropDownList1').disabled = false" GroupName="a" runat="server" /> <asp:DropDownList ID="DropDownList1" runat="server" Enabled="False"> <asp:ListItem>A</asp:ListItem> <asp:ListItem>B</asp:ListItem> </asp:DropDownList> 后台: protected void Page_Load(object sender, EventArgs e) { if (Request.Form[this.DropDownList1.UniqueID] != null) { this.DropDownList1.Enabled = true; } else this.DropDownList1.Enabled = false; }
cpp2017 2007-05-24
  • 打赏
  • 举报
回复
在这客户端做了以后,只要一提交,后台的状态还是不会变的.
babyrockxray 2007-05-24
  • 打赏
  • 举报
回复
用js就可以实现
page load里面:
RadioButton1.Attributes.Add("onclick", "test('RadioButton2')");
RadioButton2.Attributes.Add("onclick", "test('RadioButton2')");
RadioButton3.Attributes.Add("onclick", "test('RadioButton2')");

aspx:
function test(id)
{
if(document.getElementById(id).checked)
{
document.getElementById('DropDownList1').disabled = false;
}
}

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧