Asp.net asp:RadioButtonList和jQuery显示隐藏面板
我有一个名为RBLDependents的asp:RadioButtonList 它呈现如下,一个面板pnldependents,我需要在单选按钮选择为“否”时隐藏它,在单选按钮选择为“是”时显示它。我试过论坛上的一些片段,但没有一个能很好地工作。有人能帮我吗Asp.net asp:RadioButtonList和jQuery显示隐藏面板,asp.net,jquery,radiobuttonlist,Asp.net,Jquery,Radiobuttonlist,我有一个名为RBLDependents的asp:RadioButtonList 它呈现如下,一个面板pnldependents,我需要在单选按钮选择为“否”时隐藏它,在单选按钮选择为“是”时显示它。我试过论坛上的一些片段,但没有一个能很好地工作。有人能帮我吗 <table id="ctl00_ContentPlaceHolder1_ctl02_rblDependants" border="0" style="border-width:0px;"> <tr&
<table id="ctl00_ContentPlaceHolder1_ctl02_rblDependants" border="0" style="border-width:0px;">
<tr>
<td><input id="ctl00_ContentPlaceHolder1_ctl02_rblDependants_0" type="radio" name="ctl00$ContentPlaceHolder1$ctl02$rblDependants" value="Yes" /><label for="ctl00_ContentPlaceHolder1_ctl02_rblDependants_0">Yes</label></td>
</tr><tr>
<td><input id="ctl00_ContentPlaceHolder1_ctl02_rblDependants_1" type="radio" name="ctl00$ContentPlaceHolder1$ctl02$rblDependants" value="No" checked="checked" /><label for="ctl00_ContentPlaceHolder1_ctl02_rblDependants_1">No</label></td>
</tr>
</table>
<div id="ctl00_ContentPlaceHolder1_ctl02_pnlDependants">
<div class="QuestionWrapper">
<div class="Question">
<label for="">No. of Dependants</label>
</div>
<div class="Answer">
<input name="ctl00$ContentPlaceHolder1$ctl02$txtNoOfDependants" type="text" maxlength="2" id="ctl00_ContentPlaceHolder1_ctl02_txtNoOfDependants" />
</div>
<div class="ClearFloat"></div>
</div>
对
不
受养人人数
类似的方法应该可以:
$("table[id$=_rblDependants] :radio").change(function() {
$(this).closest('table').next().toggle(this.checked && this.value == 'Yes');
}).change();
这将适用于任何数量的重复控件,因为它会相对地查找
。我们所做的一切都是通过一个
谁的ID\u rbldependents
,利用其中的任何按钮并绑定到他们的事件。然后,它们中的任何一个都会被更改,检查结果是否为value=“Yes”
,如果是这样,则显示面板,否则通过隐藏面板
和将转到
,然后转到下一个元素
,因为这是您要隐藏/显示的内容。最后的操作是最初触发处理程序,因此如果最初选中“否”,则会隐藏加载时的