【发布时间】:2014-07-04 17:40:48
【问题描述】:
我最初试图隐藏一组表单域。然后,如果选择了单选按钮,则显示该组字段。然后,如果取消选择该收音机,请再次隐藏它们。
前两个工作正常(最初隐藏字段,如果选择了收音机,则显示它们)。但是当取消选择收音机时,我无法让它们再次隐藏。我确定我遗漏了一些明显的东西,但我无法弄清楚它是什么。
$(document).ready(function() {
toggleFields(); //call this first so we start out with the correct visibility depending on the selected form values
//Hide the fields initially
$("#bsd-field-custom-105966-group").hide();
$("#bsd-field-custom-105967-group").hide();
$("#bsd-field-custom-105968-group").hide();
$("#bsd-field-custom-105978").hide();
$("#bsd-field-custom-105969-group").hide();
$("#bsd-field-custom-105970").hide();
$("#bsd-field-custom-105979").hide();
$("#bsd-field-custom-105971-group").hide();
$("#bsd-field-custom-105972").hide();
//Show the fields only if lodging is required
$("#custom-105965_0").change(function () {
toggleFields();
});
});
//this toggles the visibility of the other lodging fields depending on the current selected value of the "lodging required" field
function toggleFields() {
if ($(("#custom-105965_0").checked)) {
$("#bsd-field-custom-105966-group").show();
$("#bsd-field-custom-105967-group").show();
$("#bsd-field-custom-105968-group").show();
$("#bsd-field-custom-105978").show();
$("#bsd-field-custom-105969-group").show();
$("#bsd-field-custom-105970").show();
$("#bsd-field-custom-105979").show();
$("#bsd-field-custom-105971-group").show();
$("#bsd-field-custom-105972").show();
}
else {
$("#bsd-field-custom-105966-group").hide();
$("#bsd-field-custom-105967-group").hide();
$("#bsd-field-custom-105968-group").hide();
$("#bsd-field-custom-105978").hide();
$("#bsd-field-custom-105969-group").hide();
$("#bsd-field-custom-105970").hide();
$("#bsd-field-custom-105979").hide();
$("#bsd-field-custom-105971-group").hide();
$("#bsd-field-custom-105972").hide();
}
}
【问题讨论】:
标签: jquery radio-button toggle