我有隐藏的单选按钮,并根据用户输入显示。如果输入需要更多信息,则必须提供信息。单选按钮必须返回到默认状态
如果用户改变主意并决定不回答问题,他们仍然可以处理请求。但是,如果他们以前选择了一个单选按钮,它将保持检查状态,并将提交具有其他所需值和相关值的错误值。
因此,如果用户改变主意并决定不回答,我需要先前检查过的无线电返回空值。我知道这对你们中的一些人来说可能是一个简单的解决办法,我会很感激任何帮助或方向。谢谢。'
$(document).ready(function() {
$primarySub = $("#primarySub").hide(); // cache and hide in the same call
$primary = $("#primary").hide(); // cache and hide in the same call
$secondary = $("#secondary").hide(); // cache and hide in the same call
$("input[name=visibility]").change(function() {
$("#visibilityTrue").is(':checked') ? $primarySub.show(): $primarySub.hide(); $primary.hide(); $secondary.hide();
$("input[name=visibility]").change(function() {
$("#visibilityFalse").is(':checked') ? $primarySub.hide(): $primarySub.show(); $primary.hide(); $secondary.hide();
$("input[name=parentChild]").change(function() {
$("#primaryTrue").is(':checked') ? $primary.show(): $primary.hide();
$("input[name=parentChild]").change(function() {
$("#primaryFalse").is(':checked') ? $secondary.show(): $secondary.hide();
});
});
});
});
});
<div class="btn-group" data-toggle="buttons">
<p><strong>Visibility</strong></p>
<label class="btn btn-default">
<input name="visibility" type="radio" id="visibilityTrue" value="1">
visibilityTrue</label>
<label class="btn btn-default">
<input name="visibility" type="radio" id="visibilityFalse" value="0">
visibilityFalse</label>
</div>
<div id="primarySub" class="animate">
<div class="btn-group" data-toggle="buttons">
<p><strong>Primary Item or Sub Item?</strong></p>
<label class="btn btn-default">
<input name="parentChild" type="radio" id="primaryTrue" value="1">
primaryTrue</label>
<label class="btn btn-default">
<input name="parentChild" type="radio" id="primaryFalse" value="0">
primaryFalse</label>
</div>
</div>
<div id="primary" class="animate">
<div class="form-group">
<label for="primary">Choose The Order For Primary Item</label>
<select class="form-control" name="primary" id="primary">
<option value="1">Primary First</option>
<option value="2">Primary Second</option>
<option value="3">Primary Third</option>
<option value="4">Primary Fourth</option>
</select>
<span id="helpBlock" class="help-block">Please Select One</span>
</div>
</div>
<div id="secondary" class="animate">
<div class="form-group">
<label for="secondary">Please Select One</label>
<select class="form-control" name="secondary" id="secondary">
<option value="1">Sub First</option>
<option value="2">Sub Second</option>
<option value="3">Sub Third</option>
<option value="4">Sub Fourth</option>
</select>
<span id="helpBlock" class="help-block">Please Select One</span>
</div>
</div>
查看这里的小提琴[链接] https://jsfiddle.net/#&togetherjs=5Gocl1vuzl – Danimal