我有一个单选按钮
<input type="radio" name="user-type" value="Store"> <input type="radio" name="user-type" value="Brand">
我尝试编写jQuery脚本
if($("input[name=user-type]:checked").val()) == "Brand"){
$(".showstore").hide();
$(".showbrand").show();
}
并尝试过
if($("input[name=user-type]:checked").val()) == "Brand").click(function(){
$(".showstore").hide();
$(".showbrand").show();
});
并尝试过
if ( $("input[name=user-type]:radio").val() == "Brand"){
$(".showstore").hide();
$(".showbrand").show();
}
这些都没有奏效,任何改正都表示赞赏.谢谢.
UPDATE1
我试着用这种方式隐藏它们
if($("input[name=user-type]:checked").val() == "Brand"){
$(".showstore").hide();
$(".showbrand").show();
}
else if($("input[name=user-type]:checked").val() == "Store"){
$(".showstore").show();
$(".showbrand").hide();
}
解决方法
尝试以下代码 – 它基本上侦听单击radio name = user-type,并根据单击的单选按钮进行切换.
$(function () {
$('.showstore').hide();
$('.showbrand').hide();
$("input[name=user-type]:radio").click(function () {
if ($('input[name=user-type]:checked').val() == "Brand") {
$('.showstore').hide();
$('.showbrand').show();
} else if ($('input[name=user-type]:checked').val() == "Store") {
$('.showstore').show();
$('.showbrand').hide();
}
});
});
一个工作小提琴:http://jsfiddle.net/FpUSH/1/