我正在尝试根据单选按钮的选择来切换一个
元素。这是我的代码...
<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
}
});
这对我有用但是有问题...在这里,我只需要在选择的 单选按钮
上切换。使用这段代码时每个按钮都会起作用..也就是说,假设我想选择下一个单选按钮,那么它会将 DIV 切换下来。我需要做的是无论何时我选择单选按钮,我都需要切换上面的 DIV
。
有人可以告诉我如何做到这一点吗? 谢谢。