我有 2 个单选按钮,目前我检查它们的值是 6 还是 12,并隐藏/显示表格中的相关 div。
<tr>
<td>
<div class="Price6 band" style="display: none;">21.09</div>
<div class="Price12 band">21.09</div>
</td>
</tr>
<tr>
<td>
<input id="radio1" class="radio" type="radio" name="price" value="6">
<label for="radio1">£24.95</label>
<input id="radio1" class="radio" type="radio" name="price" value="12">
<label for="radio1"> £6.95</label>
</td>
</tr>
如何编辑 jquery 代码,以便检查单选按钮的值是 true 还是 false,而不是数字值?
我目前的jquery是
$(document).ready(function() {
$("input[name$='price']").click(function() {//switch bewtween price bands
var test = $(this).val();
$("div.band").hide();
$(".Price" + test).show();
});
});
最佳答案
你可以做这样的事情
$("input").change(function(){
var test = $(this).val();
if(test == '6'){
$(".Price6").show();
$(".Price12").hide();
}
if(test == '12'){
$(".Price12").show();
$(".Price6").hide();
}
});
示例: http://jsfiddle.net/QsXm5/
注意:我更改了显示的价格 div
的 #s,因为在您的示例中它们是相同的,您无法判断是否正在发生更改.
关于jquery - 检查单选按钮值是 true 还是 false 并显示隐藏 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7901975/