我在同一表行和不同的 td 中有一个复选框和禁用的单选按钮列表,并且只是在选中/取消选中复选框时尝试启用/禁用它。
<tr class = "main">
<td colspan="2">
<input id="CheckOne" type="checkOne" name="checkOne" />
<label for="CheckOne">Some Text</label>
</td>
<td align="center">
<table id="RadioButtonListOne" disabled="disabled" title="Choices" border="0">
<tr>
<td>
<span disabled="disabled">
<input id="RadioButtonListOne_0" type="radio" name="RadioButtonListOne" value="Y" disabled="disabled" />
<label for="RadioButtonListOne_0">Yes</label></span>
</td>
<td>
<span disabled="disabled"><input id="RadioButtonListOne_1" type="radio" name="RadioButtonListOne" value="N" disabled="disabled" />
<label for="RadioButtonListOne_1">No</label>
</span>
</td>
</tr>
</table>
</td>
</tr>
这就是原始服务器端 html 的样子:
<tr class = "main">
<td colspan="2">
<asp:CheckBox ID="CheckBoxOne" runat="server" Text="Some Text"/>
</td>
<td align="center">
<asp:RadioButtonList ID="RadioButtonListOne" RepeatDirection="Horizontal">
<asp:ListItem Value="Y">Yes asp:ListItem>
<asp:ListItem Value="N">No</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
由于某种原因,当我尝试做一些明显的事情时,即
$('#<%= CheckBoxOne.ClientID %>').click(function()
{
if ($(this).is(":checked"))
{
$('#<%= RadioButtonListOne.ClientID%> input:radio').removeAttr('disabled');
}
else
{
$('#<%= RadioButtonListOne.ClientID%> input:radio').attr('disabled', 'disabled');
}
});
然后不起作用,但从逻辑上讲它应该起作用。我在这里做错了什么?
最佳答案
为什么在 jquery 代码中包含 <%= RadioButtonListOne.ClientID% input:radio ,而且还缺少尾随 > 符号
$('#<%= RadioButtonListOne.ClientID%> input:radio').removeAttr('disabled');
你的jquery代码是否在同一页面中,以便在客户端下载之前由服务器处理?像 <%= RadioButtonListOne.ClientID%> 这样的东西在 php、asp 或 html.erb 等文件之外无法工作
您可以尝试将 if 检查更改为此
if ($(this).attr('checked') == 'checked')
而不是.is(':checked')
关于jquery 复选框启用/禁用单选按钮列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2329646/