我试图根据人们单击的单选按钮隐藏和显示不同的 div。
Jquery 加载正常,我尝试在页面加载时发出警报。
非常相似的代码、选择器方法等在同一目录中的页面上工作,在同一服务器上具有相同的包含
输入框代码为:
<label class="radio"><input type="radio" name="input_sandwich_choice" value="Panini">Panini</label>
<label class="radio"><input type="radio" name="input_sandwich_choice" value="Sandwich">Sandwich</label>
<label class="radio"><input type="radio" name="input_sandwich_choice" value="Baguette">Baguette</label>
div是:
<div id="div_bread_options" class="collapse span3"> <!--2.2-->
<h4>Which bread would you like?</h4>
<label class="radio"><input id="id_option_bread_white" type="radio" name="input_bread_choice" value="white">White</label>
<label class="radio"><input id="id_option_bread_brown" type="radio" name="input_bread_choice" value="brown">Brown</label>
<label class="radio"><input id="id_option_bread_granary" type="radio" name="input_bread_choice" value="granary">Granary</label>
<label class="radio"><input hidden id="id_option_bread_none" type="radio" name="input_bread_choice" value=""></label>
</div> <!--2.2-->
<div id="div_butter_options" class="collapse span3"> <!--2.3-->
<h4>Would you like butter?</h4>
<label class="radio"><input type="radio" id="id_option_butter_yes" name="input_butter_choice" value="Yes">Yes</label>
<label class="radio"><input type="radio" id="id_option_butter_no" name="input_butter_choice" value="No">No</label>
<label class="radio"><input hidden type="radio" id="id_option_butter_none" name="input_butter_choice" value=""></label>
</div> <!--2.3-->
最后 Jquery 是:
<script>
$("input[name=input_sandwich_choice]").click(function() {
var checkedValue = $("input[name='input_sandwich_choice']:checked").val();
console.log(checkedValue);
if (checkedValue == "Panini") {
$("#div_bread_options").collapse('hide');
$("#div_butter_options").collapse('show');
} else if (checkedValue == "Sandwich") {
$("#div_bread_options").collapse('show');
$("#div_butter_options").collapse('hide');
} else if (checkedValue == "Baguette") {
$("#div_bread_options").collapse('show');
$("#div_butter_options").collapse('hide');
} else {
alert("Oops.");
}
});
</script>
只是无法弄清楚为什么这不起作用......非常感谢任何帮助!谢谢