如何在发送数据时不清除html表单



我在Html中有一个表单,在发送数据后,我有一个任务是留下用户输入的信息,而不是清理表单。形式示例:

<form method="get">
<input type="search" id="search" name="req" autocomplete="off" spellcheck="false" role="combobox"
placeholder="write here" aria-live="polite"><br>
<div class="form_radio_btn">
<input id="radio-1" type="radio" name="radio" value="first" checked>
<label for="radio-1">first</label>
</div>
<div class="form_radio_btn">
<input id="radio-2" type="radio" name="radio" value="Second">
<label for="radio-2">second</label>
</div>
</form>

请建议

调用event.preventDefault()并使用js 发出http请求

<form method="get">
<input type="search" id="search" name="req" autocomplete="off" spellcheck="false" role="combobox"
placeholder="write here" aria-live="polite" value="<?php if(isset($_REQUEST['req'])){ echo $_REQUEST['req'];}?>"><br>
<div class="form_radio_btn">
<input id="radio-1" type="radio" name="radio" value="first" <?php if(isset($_REQUEST['radio']) && $_REQUEST['radio']=='first'){ echo 'checked';}?>>
<label for="radio-1">first</label>
</div>
<div class="form_radio_btn">
<input id="radio-2" type="radio" name="radio" value="Second"  <?php if(isset($_REQUEST['radio']) && $_REQUEST['radio']=='Second'){ echo 'checked';}?>>
<label for="radio-2">second</label>
</div>
</form>

或者使用Ajax

最新更新