我有一个包含此代码的复选框
<td align="right">Include In Top Sellers?</td>
<td>
<input type="hidden" name="include_top"
value="0"><input type="checkbox"
name="include_top"
id="include_top"
value="1" <?php echo (($_POST["include_top"] == "1") or ($res["include_top"] == "1")) ? "checked='checked'" : ""; ?>
autocomplete="off"/>
</td>
</tr>
我需要默认选中此复选框,但也可以取消选中此复选框,并在保存时保持未选中状态。
答案 0 :(得分:1)
这是如何从选中的复选框开始
<input type="checkbox" checked>Checkbox</input>
&#13;
答案 1 :(得分:0)
从isset PHP激活jquery
例如:
<script type="text/javascript">function uncheck(){$(#includ_top).attr('checked', false)}</script>
if(isset($_POST['submit']))
{<script>uncheck();</script>}
答案 2 :(得分:0)
您不能拥有2个同名include_top
的输入元素。
输出您的$_POST["include_top"]
和$res["include_top"]
,看看哪一个条件为真。
示例代码如下:
<td>
<!--input type="hidden" name="include_top"
value="0"-->
<?php var_dump($_POST["include_top"], $res["include_top"]); ?>
<input type="checkbox"
name="include_top"
id="include_top"
value="1" <?php echo (($_POST["include_top"] == "1") or ($res["include_top"] == "1")) ? "checked='checked'" : ""; ?>
autocomplete="off"/>
</td>
如果您希望默认为true,则应该更好地反复检查:
<?php echo (($_POST["include_top"] != "1") and ($res["include_top"] != "1")) ? "" : "checked='checked'"; ?>