【发布时间】:2014-03-24 23:40:57
【问题描述】:
我有这个向导需要显示之前发布的值
index.html
<form method="post" action="posted.php">
<input type="text" name="surname" value="" placeholder="Surname" />
<input type="text" name="firstname" value="" placeholder="Firstname" />
<input type="checkbox" name="php" />
<input type="checkbox" name="jquery" />
<input type="checkbox" name="python" />
<input type="submit" value="Submit" />
</form>
在posted.php 中我有一个类似的表格,只是这次我知道$_POST 的值
<form method="post" action="finish.php">
<input type="text" name="surname" value="<?php echo $_POST['surname']; ?>" placeholder="Surname" />
<input type="text" name="firstname" value="<?php echo $_POST['firstname']; ?>" placeholder="Firstname" />
<input type="checkbox" name="php" />
<input type="checkbox" name="jquery" />
<input type="checkbox" name="python" />
<input type="submit" value="Submit" />
</form>
我很难想出一个解决方案来显示选中的复选框。我见过几个解决方案,比如https://stackoverflow.com/a/11424091/1411148,但我想知道在 html5 或 jquery 中是否有更多解决方案。
如何显示选中的复选框?。我遇到的问题是 <input type="checkbox" name="jquery" checked /> checked 选中了复选框,并且无法添加 post 数据来显示用户选中的内容。
【问题讨论】:
-
如果你给他们一个值,你可以使用 php 在输入标签上回显“checked”属性。
<?= ($_POST['jquery'] == '[VALUE'])? "checked" : ""; ?>。只有在检查表单提交时,该值才会通过。