【发布时间】:2021-02-21 01:09:48
【问题描述】:
我正在尝试根据重力表单中单选按钮字段中的输入来显示/隐藏 div。我使用 jQuery here 找到了一个答案,它非常适用于复选框,但是,当我尝试使用单选按钮执行相同操作时,它会执行第一部分并在选择后隐藏 div,但不会显示 div再次取消选择单选按钮。
这是我正在使用的 jQuery:
jQuery(function ($) {
var trigger = $('#choice_13_1_0');
trigger.change(function(){
if ( $(this).is(":checked") ) {
jQuery(".conditional-display").hide();
} else {
jQuery(".conditional-display").show();
}
});
});
这是 Gravity 表单生成的 HTML:
<ul class="gfield_radio" id="input_13_1">
<li class="gchoice_13_1_0">
<input name="input_1" type="radio" value="Option One" id="choice_13_1_0" tabindex="1">
<label for="choice_13_1_0" id="label_13_1_0">
Option One
</label>
</li>
<li class="gchoice_13_1_1">
<input name="input_1" type="radio" value="Option Two" id="choice_13_1_1" tabindex="2">
<label for="choice_13_1_1" id="label_13_1_1">
Option Two
</label>
</li>
<li class="gchoice_13_1_2">
<input name="input_1" type="radio" value="Option Three" id="choice_13_1_2" tabindex="3">
<label for="choice_13_1_2" id="label_13_1_2">
Option Three
</label>
</li>
我将这个 div 放在页面的其他位置:
<div class="conditional-display">
Content to conditionally display based on radio field selection
</div>
In this example what should happen is that the div will be hidden when option one is selected and then show again when option two or three are selected.
【问题讨论】:
-
请包含html。
-
现在更新了! :)
-
究竟何时,您希望条件 div 可见还是不可见?
标签: jquery wordpress gravity-forms-plugin gravityforms