用于属性澄清的HTML5标签

编程入门 行业动态 更新时间:2024-10-26 02:30:12
本文介绍了用于属性澄清的HTML5标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

来自HTML5最终规范的引用( http:// www .w3 / TR / html5 / forms.html#attr-label-for ):

A quote from HTML5 final specification (www.w3/TR/html5/forms.html#attr-label-for):

for 属性以指示与标题相关联的表单控件。如果指定了该属性,则该属性的值必须是与该标签位于同一Document中的 labelable元素的 ID 元件。如果指定了该属性,并且Document中的元素 ID 等于 属性的值,和第一个这样的元素是可标记元素,然后该元素是标签元素的标记控件。

The for attribute may be specified to indicate a form control with which the caption is to be associated. If the attribute is specified, the attribute's value must be the ID of a labelable element in the same Document as the label element. If the attribute is specified and there is an element in the Document whose ID is equal to the value of the for attribute, and the first such element is a labelable element, then that element is the label element's labeled control.

最后一句话措辞奇怪:它在单个元素中谈到第一个这样的元素并且似乎意味着可以有更多比具有相同ID的文档中的单个元素。粗体部分是否被视为和那个元素?

The last phrase is worded strangely: it talks about "the first such element" among a single element and seems to imply that there can be more than a single element in a document with the same ID. Was the part in bold meant to be read as "and that element"?

编辑。回答我的问题的人似乎相信规范正在定义一个行为,以防其中一个规范规则(唯一ID)被破坏。这对我来说听起来完全不可信。如果你违反了规范中的规则,那么你就要自担风险并获得未定义的行为。我从来没有看到过这样的规范:这是规则,但是如果你打破它,不要担心,事情仍然可以这样工作。

EDIT. People answering my question seems to believe the spec is defining a behavior in case one of the spec rules (unique IDs) is broken. This sounds totally implausible to me. If you break the rules in the spec you do it at your own peril and get the undefined behavior, period. Never have I seen the spec that says: here's the rule but if you break it, don't worry, things still gonna work like so and so.

推荐答案

似乎HTML5规范中引用的短语没有拼写错误,并且确实在其他规范规则之一(ID必须唯一)被破坏的情况下定义了一种行为。以下是另一个W3C规范(W3C DOM4)的引用,其中再次考虑了文档中存在重复ID的元素(注意粗体部分):

It seems the quoted phrase from HTML5 specification does not have a typo and indeed defines a behavior in case one of the other specification rules (IDs must be unique) is broken. Here is a quote from another W3C specification (W3C DOM4) worded in a way that again takes into account the existence of elements with a duplicate IDs in a document (notice the part in bold):

www.w3/TR/dom /#dom-nonelementparentnode-getelementbyid

getElementById(elementId)方法必须以树的顺序在上下文对象的后代中返回第一个元素,其ID为 elementId ,如果没有这样的元素,则返回null否则。

The getElementById(elementId) method must return the first element, in tree order, within context object's descendants, whose ID is elementId, and null if there is no such element otherwise.

在规范规则之一(ID必须唯一)的情况下,W3C认为有必要定义行为的原因是然而,破碎仍然是一个谜。

The reason why the W3C deemed necessary to define a behavior in case one of the specification rules (IDs must be unique) is broken remains a mystery, though.

更多推荐

用于属性澄清的HTML5标签

本文发布于:2023-07-13 03:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1099769.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   标签

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!