【发布时间】:2019-09-07 11:37:48
【问题描述】:
当复选框留空时,我希望它带有值“false”,而当复选框被选中时,我希望它带有值“true”。
<label for="windscreen"><b>Windscreen</b></label>
<input class="form-control" id="windscreen" type="checkbox" name="windscreen">
<label for="heatedchairs"><b>Heated Chairs</b></label>
<input class="form-control" id="heatedchairs" type="checkbox" name="heatedchairs">
<label for="indicators"><b>Indicators</b></label>
<input class="form-control" id="indicators" type="checkbox" name="indicators">
<input class="btn btn-primary" type="submit" id="register" name="create" value="Sign up">
<script
function register {
document.getElementById("windscreen").checked = true;
document.getElementById("windscreen").checked = false;
}>
</script>
我已经为我的一个具有 id="windscreen" 的复选框尝试了这个,但它没有做任何事情
当复选框被选中时,它会返回值 true,当它被取消选中时,它会返回值 false。因此,在数据库中,它将被保存为 false 或 true,而不是像现在那样全部“打开”
【问题讨论】:
-
而不是像现在那样全部“开启”-->请解释一下。也可能是您对数据库保存代码有疑问。所以在这里也添加它
-
你见过stackoverflow.com/questions/6204885/… 吗?请修复应该是
<script>和<script code here>的脚本标签
标签: php