简体   繁体   English

复选框未显示为已选中状态,即使显示为已选中

[英]Checkbox is not displaying as checked, even though it is

I have PHP script that sets checked="checked" to checkboxes based on the database record. 我有一个PHP脚本,它根据数据库记录将checked="checked"为复选框。 However all, but the first occurence of the checked checkbox are displaying checked. 但是,除了第一次出现的所有复选框,都显示为已选中。 Here is what HTML looks like when it browser parses it: 这是HTML浏览器对其进行解析时的外观:

<input type="checkbox" id="not_online"><label for="not_online">Not Online</label>
<input type="checkbox" id="facebook" checked="checked"><label for="facebook">Facebook</label>
<input type="checkbox" id="twitter" checked="checked"><label for="twitter">Twitter</label>

And this is what I see in FF26.0 这就是我在FF26.0中看到的

[ ] Not Online
[ ] Facebook
[×] Twitter

What could cause the issue? 是什么原因引起的?

Add name to each of your checkbox fields: 为每个复选框字段添加name

<input type="checkbox" id="not_online" name="not_online"><label for="not_online">Not Online</label>
<input type="checkbox" id="facebook" name="facebook" checked="checked"><label for="facebook">Facebook</label>
<input type="checkbox" id="twitter" name="twitter" checked="checked"><label for="twitter">Twitter</label>

Its is working fine for me what problem are you having? 它对我来说很好,您有什么问题? Here is my fiddle http://jsfiddle.net/dbDj3/ 这是我的小提琴http://jsfiddle.net/dbDj3/

using your code 使用您的代码

    <input type="checkbox" id="not_online"><label for="not_online">Not Online</label>
    <input type="checkbox" id="facebook" checked="checked"><label for="facebook">Facebook</label>
    <input type="checkbox" id="twitter" checked="checked"><label for="twitter">Twitter</label>

It must be some other part of your code that is causing problems 一定是导致问题的代码的其他部分

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

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