我有隱藏的單選按鈕,並根據用戶輸入顯示。如果輸入需要更多信息,則必須提供信息。單選按鈕必須返回到默認狀態
如果用戶改變主意並決定不回答問題,他們仍然可以處理請求。但是,如果他們以前選擇了一個單選按鈕,它將保持檢查狀態,並將提交具有其他所需值和相關值的錯誤值。
因此,如果用戶改變主意並決定不回答,我需要先前檢查過的無線電返回空值。我知道這對你們中的一些人來說可能是一個簡單的解決辦法,我會很感激任何幫助或方向。謝謝。'
$(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