我想创建一个默认情况下始终未选中的复选框,用户不应选中它。我不想禁用该复选框,因为我想在提交表单时传递该复选框的值。请建议。 下面的代码不起作用:
<input type="checkbox" id="chkbox1" name="chkbox1" value="unChecked" checked="false" readonly="readonly">
由于上述代码复选框始终处于选中状态,我希望该复选框始终处于未选中状态,用户不应该选择它。我也不应该使用禁用选项,因为我想在提交表单时发送复选框的值.谢谢。
最佳答案
只需删除 checked
属性即可
<input type="checkbox" id="chkbox1" name="chkbox1" value="unChecked" readonly="readonly" />
使用任何字符串值(甚至 false)设置 checked
属性都会使复选框处于选中状态
i want the checkbox always be unselected and users should not able to select it.I should not use the disable option too as i want to send the value of checkbox when i submit the form
听起来你根本不需要一个复选框,而只是一个发送值的隐藏输入
<input type="hidden" name="chkbox1" value="unChecked" />
关于javascript - 默认情况下取消选中复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24892293/