HTML - 为什么不是不确定=“不确定|真”受尊重?
我想使用复选框的不确定属性。更改 JavaScript 中的值适用于各种浏览器(甚至 MSIE6!),但是,我无法通过 any 中的 HTML 属性设置初始值。
这是设计使然吗? 如果是这样,为什么?在服务器端,我可以确定它是不确定的。那么,为什么我不能告诉浏览器呢?如果长时间运行的脚本保留了属性设置,浏览器供应商难道不担心 FOUC(无样式内容的闪烁)吗?
这是一个工作示例: http://jsfiddle.net/KUQC9/1/
I want to use the indeterminate property of a checkbox. Changing the value in JavaScript works in all sorts of browsers (even MSIE6!), however, I cannot set the initial value via HTML attributes in any.
Is this by design? If so, why? On server side, I can determine that it's indeterminate. So, why can't I tell the browser? Weren't browser vendors worried about FOUCs (Flashes Of Unstyled Content) if a long-running script holds up the property-setting?
Here's a working example: http://jsfiddle.net/KUQC9/1/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法通过 HTML 设计使复选框变得不确定。请参阅 css-tricks.com 上的这篇文章,其中深入讨论了该主题。
至于你的问题的“为什么”部分,W3C 邮件列表上有一些信息可能会有所帮助:
不确定
HTML正如您在示例中所示,我可以在这里找到“内容”属性:。这是值得的,实际上有一个
:infiniteate
CSS 选择器(它似乎像其他 CSS 伪类一样对待,如:visited
,它也不能直接通过 HTML 设置,所以也许这也是indefinate
不能成为的另一个原因)。在 CSS 选择器的演示中,W3C 本身使用了与您大致相同的方法:W3C 不确定 CSS 选择器演示。鉴于此,我想说您正在使用可用于设置复选框的不确定状态的最佳方法You can't make a checkbox indeterminate through HTML by design. See this article on css-tricks.com, which discusses the topic in depth.
As for the "why" part of your question, there is some information on the W3C mailing lists that may be helpful:
indeterminate
HTML "content" attribute, as you show in your example, that I could find was here:For what it's worth, there is in fact an
:indeterminate
CSS selector (it seems to be treated like other CSS pseudo-classes like:visited
, which also cannot be set through HTML directly, so maybe that is another reasonindeterminate
can't be either). In its demo of the CSS selector the W3C itself uses about the same approach that you do: W3C indeterminate CSS selector demo. In light of that, I'd say you're using about the best method available for setting the indeterminate state of a check box这是设计使然。表示复选框状态的唯一 HTML 方式是通过 selected 属性;这是因为复选框意味着真/假,而不是真/假/未知。可以通过 JavaScript 来标记不确定的内容,但它不会更改复选框的实际/提交值。
如果您确实想将复选框初始化为不确定,则需要使用 Javascript 来完成(我想是在加载事件上)。
It is by design. The only HTML way to denote checkbox state is through the checked attribute; this is because checkbox is meant to true/false, rather than true/false/unknown. Marking something indeterminate can be done via Javascript, but it will not change the actual/sumbitted value of the checkbox.
If you really want to initialize checkboxes to indeterminate, you'll need to do it with Javascript (I would imagine on the load event).