作者saluyi (JOJO)
看板Ajax
标题Re: [问题] RadioButton选取之後的控制项致能与否??
时间Sat Aug 4 12:02:52 2012
你主要问题是在於
asp.net的元件id跟实际在cient端的id是不一样的
例如你的DropDownList在server上他的id是DropDownList1
但是在server render HTML的时候 他其实还是一个 <input>
然後他的id也会被改变
而javascript 是在cient执行的语言
所以你去找DropDownList1 跟 DropDownList2这两个id其实是不存在的
你必须要用<%= DropDownList1.ClientID %>来获得他cient的id
这是asp.net为了确保id的唯一性的关系
※ 引述《kiyasuto1 (kiy)》之铭言:
: 各位前辈好,小弟写ASP.NET遇到一的问题
: 有关JAVASCRIPT如下
: function fncEnable() {
: if (RadioButton1.checked) {
: document.DropDownList1.disabled = false;
: document.DropDownList2.disabled = true;
: }
: else {
: document.DropDownList1.disabled = true;
: document.DropDownList2.disabled = false;
: }
: }
: 而HTML档如下
: <asp:RadioButton ID="RadioButton1" runat="server" Onclick="fncEnable()"
: GroupName="r"/>
: <asp:RadioButton ID="RadioButton2" runat="server" GroupName="r" />
: <br />
: <asp:DropDownList ID="DropDownList1" runat="server" >
: </asp:DropDownList>
: <asp:DropDownList ID="DropDownList2" runat="server" >
: </asp:DropDownList>
: 但是都没有反应...请前辈不吝指教!!感谢~
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 124.9.129.212
1F:→ kiyasuto1:那我要怎麽改呢??? 08/04 12:10
2F:→ glennchen:本文已经解释怎麽解啦 08/04 16:40