我对javascript很陌生,并且还在尝试获取api与后端进行交互。我已经选中了一些复选框,如果要选择它们的值,我想将它们的值存储在数组中(以json格式),还将选择要在输入框中输入的值,然后使用fetch api将其发送到后端的数组。用于进行处理。任何人都可以在这里帮助我。
$("#step1").click(function() {
$("#checked1").css("display","initial");
$("#checked1").toggle($(this).prop("checked"));
});
$("#step2").click(function() {
$("#checked2").css("display","initial");
$("#checked2").toggle($(this).prop("checked"));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<p> Ready to start </p>
<div class="form-check checkbox-rounded checkbox-filled">
<input type="checkbox" class="form-check-input filled-in" value="Yes" name="demo" id="Yes">
<label class="form-check-label" for="Yes">Yes</label>
</div>
<div class="form-check checkbox-rounded checkbox-filled">
<input type="checkbox" class="form-check-input filled-in" value="step1" name="demo" id="step1">
<label class="form-check-label" for="step1">Check to start step1</label>
<div id ="checked1" style="padding-left:20px; display: none;" class="custom-control-inline">
<input type="text" id="inputvalue" class="form-control form-centrol-sm" style="width: 60%; display: inherit;" placeholder="Enter your name">
<hr style="margin-top: 0.5rem !important; margin-bottom: 0.5rem !important;">
</div>
</div>
<div class="form-check checkbox-rounded checkbox-filled">
<input type="checkbox" class="form-check-input filled-in" value="step2" name="demo" id="step2">
<label class="form-check-label" for="step2">Check to start step2</label>
<div id ="checked2" style="padding-left:20px; display: none;" class="custom-control-inline">
<input type="text" id="inputvalue" class="form-control form-centrol-sm" style="width: 60%; display: inherit;" placeholder="Enter your age">
<hr style="margin-top: 0.5rem !important; margin-bottom: 0.5rem !important;">
</div>
</div>