简体   繁体   English

禁用复选框后,复选框不保持选中状态

[英]Checkbox does not hold checked status after disabling the checkbox

I have form with checkbox used in both add/edit mode but have scenario when in edit mode disable the checkbox with its value like checked or unchecked. 我在添加/编辑模式下都使用了带有复选框的表单,但是在编辑模式下禁用了复选框,使其具有选中或未选中的值。

I have tried as below but not succeeded, 我已经尝试了以下方法,但没有成功,

<input type="checkbox" disabled="disabled" checked="checked">

If an element is disabled, it's value is not posted along with the form, so while the checkbox appears checked, that information is not in the form data. 如果禁用了元素,则其值不会与表单一起发布,因此,当复选框显示为选中时,该信息不在表单数据中。

You may want to store the value in a hidden element, or (better, I think), let the server side script determine the proper default value if it is omitted. 您可能希望将值存储在一个隐藏元素中,或者(最好,我认为),如果省略了服务器端脚本,则请确定适当的默认值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM