テキスト入力の横にたくさんのラジオ ボタンがあります。ラジオ ボタンの状態が変更されると、「.IdPassportRadioButton」のクラスを持つすべてのラジオ ボタンを取得するメソッドを実行します。ラジオ ボタンごとに、次のテキスト入力を見つけて、ラジオ ボタンに応じてその入力を有効または無効にしたいと考えています。
HTML は次のようになります。
<div class="editor-container" style="">
<div class="editor-label">
<%=Html.RadioButtonFor(m => m.IsPassport, false,
new { @class = "IdPassportRadioButton" })%>
ID Number
</div>
<div class="editor-field">
<%=Html.TextBoxFor(m => m.IdentityNumber,
new { @class = "textbox IdPassportTextBox"})%>
</div>
</div>
JQuery メソッド:
$(".IdPassportRadioButton").each(function() {
if ($(this).is(":checked")) {
$(this).next(".IdPassportTextBox").removeAttr("disabled");
} else {
$(this).next(".IdPassportTextBox").attr("disabled", "disabled");
}
});
ご覧のとおり、次の TextBox をクラス ".IdPassportTextBox" で検索しようとしましたが、うまくいきません。次のテキストボックスを取得する行を除いて、すべてが機能します。
助言がありますか