我是 PHP 和 Javascript 的新手,刚开始创建一个有两种形式的网站,一种有 5 个复选框,另一种有 5 个单选按钮。当您更改选择的单选按钮时,它会刷新页面并使用新值。复选框也是如此。不幸的是,如果您更改其中一个表单,然后更改另一个表单,则第一个表单的值将不再存在。
这是代码:
<form name='form2' method='post'>
<input type="radio" name="group1" value="all" onClick="if (this.checked) this.form.submit();" <?php if ($_REQUEST['group1'] == null || $_REQUEST['group1'] == "all"){ echo "checked='checked'";}?>/> All<br>
<input type="radio" name="group1" value="Example" onClick="if (this.checked) this.form.submit();" <?php if ($_REQUEST['group1'] == "Example"){ echo "checked='checked'";}?>/> Example<br>
<input type="radio" name="group1" value="clifton" onClick="if (this.checked) this.form.submit();" <?php if ($_REQUEST['group1'] == "clifton"){ echo "checked='checked'";}?>/> Clifton<br/>
<input type="radio" name="group1" value="fruita" onClick="if (this.checked) this.form.submit();" <?php if ($_REQUEST['group1'] == "fruita"){ echo "checked='checked'";}?>/> Fruita<br/>
<input type="radio" name="group1" value="loma" onClick="if (this.checked) this.form.submit();" <?php if ($_REQUEST['group1'] == "loma"){ echo "checked='checked'";}?>/> Loma<br/>
</form>
<form name='form3' method='post'>
<input type="checkbox" name="option1" value="smoking" onClick="if (this.checked) this.form.submit();" <?php if(isset($_REQUEST['option1'])){ echo "checked='checked'";} ?>/> No Smoking<br>
<input type="checkbox" name="option2" value="kids" onClick="if (this.checked) this.form.submit();" <?php if(isset($_REQUEST['option2'])){ echo "checked='checked'";} ?>/>Good for Kids<br>
<input type="checkbox" name="option3" value="wheelchair" onClick="if (this.checked) this.form.submit();" <?php if(isset($_REQUEST['option3'])){ echo "checked='checked'";} ?>/>Wheelchair Accessible<br>
<input type="checkbox" name="option4" value="alcohol" onClick="if (this.checked) this.form.submit();" <?php if(isset($_REQUEST['option4'])){ echo "checked='checked'";} ?>/>Serves Alcohol<br>
<input type="checkbox" name="option5" value="delivery" onClick="if (this.checked) this.form.submit();" <?php if(isset($_REQUEST['option5'])){ echo "checked='checked'";} ?>/>Delivery Servicee<br>
</form>
我试图让两个表单输入都被保留,即使另一个表单发生变化。任何帮助将不胜感激。谢谢!