我正在使用下面的代码在添加到输入的伪类“:checked”上显示或隐藏一个div(在我的例子中是复选框和单选按钮)。目前,它与复选框完美配合(div 的显示/隐藏正确切换)但是,一旦单击单选按钮,div 将显示,但在单击其他单选按钮时不会隐藏。
jQuery:
$(document).ready(function(){
// Hide hospitalInfo DIV
$("#hospitalInfo").css("display","none");
// Add onclick handler to checkbox w/id checkme
$(".hospCheck").click(function(){
// If checked
if ($(".hospCheck").is(":checked")) {
//show the hidden div
$("#hospitalInfo").show("fast");
} else {
//otherwise, hide it
$("#hospitalInfo").hide("fast");
}
});
});
这是HTML:
<input type="radio" name="ini_disposition" value="H" class="hospCheck" />
<input type="radio" name="ini_disposition" value="S" />
<input type="radio" name="ini_disposition" value="T" />
<input type="checkbox" class="hospCheck" name="er" value="Y">
<input type="checkbox" class="hospCheck" name="er" value="N">
<div id="hospitalInfo">
Text I want to hide or show.
</div>
任何见解表示赞赏!