【发布时间】:2020-07-19 23:32:28
【问题描述】:
提交表单后如何保持复选框处于选中状态? 我尝试使用这种方法:
<input type = "checkbox" name="math[]" value="Addition" <?php if(isset($_POST['math'])) echo "checked='checked'";?>/>Addition<br>
但即使我只选择一个,我的所有复选框都会保持选中状态,这是我的代码:
<form id="calc" action="calculator.php" method="POST" >
<b>Enter First No: <br>
<input type = "text" name="num1" value="<?php if(isset($_POST['num1'])){echo $num1;} ?>" required="required"/><br>
Enter Second No: <br>
<input type = "text" name="num2" value="<?php if(isset($_POST['num2'])){echo $num2;} ?>" required="required"/><br>
<b>Select Operation: <br>
<input type = "checkbox" name="math[]" value="Addition" <?php if(isset($_POST['math'])) echo "checked='checked'";?>/>Addition<br>
<input type = "checkbox" name="math[]" value="Subtraction" <?php if(isset($_POST['math'])) echo "checked='checked'";?>/>Subtraction<br>
<input type ="submit" value="compute" name="btnsubmit"> <br>
谢谢!
【问题讨论】:
-
请编辑您的帖子并将您的 html 放入 html 或代码块中
-
对不起,我忘了把它放在括号里,,,,我是新手
-
尝试将 required="required" 改为 required
-
@BarclickFloresVelasquez 它不会改变任何东西