[英]Dynamically add attribute for radiobutton
我有一個帶有3個單選按鈕和文本框的用戶控件。 如果選擇了RB1,我將顯示文本框。 對於其余兩個選項,我將隱藏文本框。
<asp:RadioButton ID="rbAPL" runat="server" Checked="true" CssClass="tablecelldata"
GroupName="ServiceType" Text="Testing of Animal Pathogens & Veterinary Biologics" /><br />
<asp:RadioButton ID="rbVPHL" runat="server" CssClass="tablecelldata" GroupName="ServiceType"
Text="Food Testing and Export Health Certification (Veterinary Health Certificate for Meat, Fish & Dairy Products)" /><br />
<asp:RadioButton ID="rbPHL" runat="server" CssClass="tablecelldata" GroupName="ServiceType"
Text="Plant Health Diagnosis Services" />
和文本框
<asp:TextBox ID="tbxApplicationRefNo" runat="server" Width="350px"></asp:TextBox>
我想動態設置單選按鈕的屬性以顯示或隱藏文本框。 我該怎么辦?
預先感謝您的答復!
我會在后面的代碼中執行以下操作:
public void rbAPL_CheckedChanged(object sender, EventArgs e)
{
RadioButton button = sender as RadioButton;
if (button.Checked)
{
tbxApplicationRefNo.Visible = true;
}
}
單擊時將“文本框”設置為“可見”。
1將處理程序添加到單選按鈕的js-onclick事件
2使用jquery進行顯示/隱藏(例如:“ $('#id')。show();”)
3最初注意TextBox是隱形cos RB1
<asp:RadioButton ID="rbAPL" runat="server" Checked="true" CssClass="tablecelldata" GroupName="ServiceType" Text="Testing of Animal Pathogens & Veterinary Biologics" onclick='<%# string.Format("$('#{0}').hide();", tbxApplicationRefNo.ClientID) %>' />
<br />
<asp:RadioButton ID="rbVPHL" runat="server" CssClass="tablecelldata" GroupName="ServiceType" Text="Food Testing and Export Health Certification (Veterinary Health Certificate for Meat, Fish & Dairy Products)" onclick='<%# string.Format("$('#{0}').show();", tbxApplicationRefNo.ClientID) %>' />
<br />
<asp:RadioButton ID="rbPHL" runat="server" CssClass="tablecelldata" GroupName="ServiceType" Text="Plant Health Diagnosis Services" onclick='<%# string.Format("$('#{0}').show();", tbxApplicationRefNo.ClientID) %>' />
<br />
<asp:TextBox style="display:none" ID="tbxApplicationRefNo" runat="server" Width="350px" Text="hello :)"></asp:TextBox>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.