【发布时间】:2019-11-16 22:08:45
【问题描述】:
我有一个包含 3 个项目的 asp.net RadioButtonList。当用户单击我希望触发我的 JQuery 并获取选择了哪个单选按钮的任何项目时,我将使用该值来确定隐藏/显示 <div>。
这是我的 RadioButtonList 的样子:
asp:RadioButtonList ID="rblAnswers" runat="server"
RepeatDirection="Horizontal"
CssClass="form-control FormatRadioButtonList"
RepeatLayout="Table">
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
<asp:ListItem>Maybe</asp:ListItem>
</asp:RadioButtonList>
这是我的 JQuery 事件:
$(document).ready(function () {
$('#<%=rblAnswers.ClientID %>').change(function () {
$(this).click(function () {
alert((this).value);
});
});
});
但是它似乎不起作用,我什至尝试只显示一条警报消息,看看我是否可以让我的 Jquery 命中(我有其他 Jquery 在其他地方工作,所以我知道它已链接到我的项目中正确。)
$('#<%=rblAnswers.ClientID %>').change(function () {
alert("TEST");
});
我哪里错了?如何在我的单选按钮列表上使用 Jquery 更改事件来获取所选单选按钮的值?
编辑
这是在 html 中呈现的方式
<table id="ctl00_ContentPlaceHolder2_rblAnswers" class="form-control FormatRadioButtonList">
<tbody>
<tr>
<td>
<input id="ctl00_ContentPlaceHolder2_rblAnswers_0" type="radio" name="ctl00$ContentPlaceHolder2$rblRework" value="Yes">
<label for="ctl00_ContentPlaceHolder2_rblAnswers_0">Yes</label>
</td>
<td>
<input id="ctl00_ContentPlaceHolder2_rblAnswers_1" type="radio" name="ctl00$ContentPlaceHolder2$rblAnswers" value="No">
<label for="ctl00_ContentPlaceHolder2_rblAnswers_1">No</label>
</td>
<td>
<input id="ctl00_ContentPlaceHolder2_rblAnswers_2" type="radio" name="ctl00$ContentPlaceHolder2$rblAnswers" value="Maybe">
<label for="ctl00_ContentPlaceHolder2_rblAnswers_2">Maybe</label>
</td>
</tr>
</tbody>
【问题讨论】:
-
您确定
'#<%=rblRework.ClientID %>'以您期望的方式呈现吗?