像“图片 1”中那样有 20 多个字段。如果选择“是”,则显示“图片 2”中的表格。所以我有 20 个是/否字段和 20 个不同的表。如果选择是,我如何显示表格。我已经为单个字段尝试了一些代码。由于有很多字段,我想知道有什么方法可以使代码最少化和更简单。这是我尝试过的代码:
CSS:
#show-dc-table {
display: none;
}
脚本:
<script>
$(document).ready(function() {
$('.form-check-inline input[type="radio"]').click(function() {
if ($(this).attr('id') == 'allergy-yes') {
$('#show-dc-table').show();
} else {
$('#show-dc-table').hide();
}
});
});
</script>
HTML:
<div class="form-group row">
<label class="col-sm-2 col-form-label">Do you have Allergies </label>
<div class="col-sm-10">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="allergy" value="Yes" id="allergy-yes">
<label class="form-check-label">Yes</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="allergy" value="No">
<label class="form-check-label">No</label>
</div>
</div>
</div>
<table class="table table-striped" id="show-dc-table">
<tr>
<th scope="col">Alergic Reactions to</th>
<th scope="col">Yes</th>
<th scope="col">No</th>
<th scope="col">Notes</th>
</tr>
</table>
素胚勾勒不出你
慕沐林林
相关分类