ラジオ ボタン リストの値が「N」の場合、ラベル コントロールを表示/非表示にしようとしています。コードは正常に動作しますが、ラジオ ボタンのチェックを外すと、Label コントロールが非表示になりません。また、Jquery mousedown イベントを使用して選択をクリアしています。提案してください。
var radioList = "#<%= radioLst1.ClientID %>";
var lblID = document.getElementById('<%=LblIDNumber.ClientID%>');
$(radioList + " input:radio").click(function (e) {
if ($('#<%= radioLst1.ClientID %> input:checked').val() == "N") {
lblID.style.display = $(this).attr("checked") ? 'inline' : 'none';
}
else {
lblID.style.display = 'none';
}
});
次のコードを使用して、ラジオ ボタン リストの選択をクリアしています。
$(radioList + " input:radio").mousedown(function (e) {
if ($(this).attr("checked") == true) {
setTimeout("$('input[id=" + $(this).attr('id') + "]').removeAttr('checked');", 200);
lblID.style.display = 'none';
}
else {
return true
}
});
<asp:Label ID="LblIDNumber" style="display:none" runat="server">Number</asp:Label>
<asp:RadioButtonList ID="radioLst1" runat="server">
<asp:ListItem Value="U">Unknown</asp:ListItem>
<asp:ListItem Value="N">Not Applicable</asp:ListItem>
</asp:RadioButtonList>