jQuery checkbox matching radiobuttonlist
On my pages I have a table with rows that typically look like this:
<tr class = "child">
<td>
<asp:CheckBox ID="CheckBoxEyeProblems" runat="server" />
</td>
<td align="center">
<asp:RadioButtonList ID="RadioButtonListEyeProblems"
<asp:ListItem Value="Y">Yes</asp:ListItem>
<asp:Lis开发者_如何学运维tItem Value="N">No</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
What I am trying to do is to disable/enable radiobuttonlist in the same row as the checkbox when you check/uncheck it.
$('tr.child input:checkbox').click(function()
{
//last part of this selector is incorrect, how to correct it here?
var rblist = $(this).closest('tr.child').find(':input:radio');
if ($(this).is(':checked'))
{
//aslo not sure how to clear selection if any from RadioButtonList here
rblist.attr('disabled', 'disabled');
}
else
{
rblist.removeAttr('disabled');
}
});
So, those are the problems I have. I am using ASP.NET 3.5.
Try this
$("tr.child td input:checkbox").click(function(){
var chk = $(this);
//chk.closest("td").next().find("input:radio").attr("disabled",chk.attr("checked"));
// to remove checked attribute you can use
chk.closest("td").next().find("input:radio").attr("checked", false).attr("disabled",chk.attr("checked"));
});
精彩评论