DIV
の選択に応じてを切り替えようとしていますradio buttons
。これが私のコーディングです。
<div class="form-element-row">
<div class="first-child">
<label for="name">Registration Period :</label>
</div>
<div class="last-child">
<input type="radio" name="period" value="1" />1 Year
<input type="radio" name="period" value="2" />2 Years
<input type="radio" name="period" value="3" />3 Years
</div>
</div>
<div class="subscription_rate">
<div class="first-child">
<label> </label>
</div>
<div class="last-child">
<table>
<tr>
<th>Subscription Rate</th>
<th>1 Year</th>
<th>2 Years</th>
<th>3 Years</th>
</tr>
<tr>
<td>Rates for subscription period.</td>
<td>$ 3000</td>
<td>$ 4500</td>
<td>$ 7500</td>
</tr>
</table>
</div>
</div>
これはjqueryです
$('.subscription_rate').hide(); // hide the div first
$('input[type=radio]').click(function(){
if($('input[type=radio]:checked')){
$('.subscription_rate') .slideToggle('slow') // show it when user clicks the radio buttons
}else{
$('.subscription_rate') .fadeOut("slow"); // if in any case radio button is not checked by user hide the div
}
});
これは私にとってはうまくいっていますが、問題があります。ここでは、選択したをクリックするだけで切り替える必要がありますradio button
。このコードを使用すると、すべてのボタンで機能します。つまり、次のラジオボタンを選択してから、DIVを切り替えます。これで行う必要があるのは、常に、を切り替える必要のあるラジオボタンを選択していることDIV
です。
誰かが私にこれをどのように行うことができるか教えてもらえますか..ありがとう。