グーグルを検索してオーバーフローを積み上げ、いくつかの良い提案を見つけましたが、何を試してもうまくいきません。基本的に、ラジオ グループが yes に設定されている場合、div を表示および非表示にしようとしています。
これを機能させるためにクラスを使用しようとしましたが、概念を誤解していると思いますが、まったく機能しません。
同様に機能するには、複数のインスタンスが必要であることに注意してください:)
要約すると、はいといいえの 2 つのラジオ ボタンが必要です。はいが選択されている場合、追加フィールドのクラスを持つ次の直接 div を表示し、ラジオ ボタンが選択されていない場合は再び非表示にする必要があります。$(this) を使用して次の .extra-field を見つけ、それのみを表示する必要があると思います
簡単に jsFiddle を作成しました - http://jsfiddle.net/andyjh07/GmYjd/以下のコードを貼り付けました:
HTML -
<label class="label2">Do you have a 2nd Occupation?</label>
<input class="checkme" type="radio" name="22. Do you have 2nd Occupation" value="Yes" />Yes
<input type="radio" name="22. Do you have 2nd Occupation" value="No" />No<br />
<div class="extra-field">
<label class="label">Secondary Occupation?</label> <input class="textbox requiredField" name="22a. If Yes - Secondary Occupation?" type="text" />
<div class="clear"> </div>
</div>
そしてjquery -
// Trigger extra fields to show depending on what checkme class is clicked
$(".checkme").on('click', function(){
$(this).next(".extra-field").fadeToggle(500);
});