简体   繁体   English

标签元素是否必须与表单相关联?

[英]Does a label element have to be associated with a form?

From the documentation of a label element : label元素的文档中

Attributes 属性

(...) (......)

for . for The id of a labelable form-related element in the same document as the <label> element. <label>元素在同一文档中的与标签有关的元素的id

Ugh. 啊。 Must this be the id of an element related to a form ? 这必须是与form相关的元素的id吗?

Why am I asking. 我为什么要问。 Well I have a select element that is not associated with any form . 好吧,我有一个select元素,它与任何form都不相关。 Value of this select does not have to be sent to the server and even when it will, it seems cumbersome for me to do this by submitting a form . select值不必发送到服务器,即使是这样,我也很麻烦通过提交form来做到这一点。 Is this incorrect? 这不正确吗? Yet I would like to somehow describe what this select does, so I want a label , but there is no form , so am I allowed to place a label ? 但是我想以某种方式描述此select作用,所以我想要一个label ,但是没有form ,所以我可以放置label吗?

Longer story, if you wish to know: Web game, players can build teams and enter battles with these teams. 更长的故事,如果您想知道:网页游戏,玩家可以建立团队并进入与这些团队的战斗。 Ultimately I want something more sophisticated, but for the sake of prototyping I now have a select element whose option s are simply teams' names. 最终,我想要更复杂的东西,但是为了进行原型设计,我现在有了一个select元素,其option只是团队的名字。 So when the player chooses a team, it is simply set as the currently active team. 因此,当玩家选择球队时,只需将其设置为当前活跃的球队。 Now they can enter the teambuilder to view it or queue in the matchmaker. 现在他们可以进入团队建设者进行查看或在媒人中排队。 If they modify the team and save it, then it will be sent to the server; 如果他们修改了团队并保存了,那么它将被发送到服务器。 and if they queue to battle the team will also be sent to server; 如果他们排队战斗,该团队也将被发送到服务器; but in both cases additional data sent alongside the team's ID will differ significantly, so I don't see how can I make this select a part of a form that may be later submitted to the server. 但是在这两种情况下,随团队ID一起发送的其他数据都将有很大的不同,因此我看不到如何select form中的一部分,然后可以将其提交给服务器。

Or do I need a form element, even if its only purpose will be to wrap a single select inside a single label ? 还是我需要一个form元素,即使它的唯一目的是将单个select包装在单个label

That description does not imply that a label must be associated with a form-related element that is a descendant of a form via its for attribute. 该描述并不意味着label必须通过其for属性与作为form后裔的form相关元素相关联。 It's saying that it must be associated with an element that is typically used in forms. 也就是说,它必须与表单中通常使用的元素相关联。 Most, though not all, of these elements are also known as form controls . 这些元素中的大多数(尽管不是全部)也称为表单控件 Neither the label nor its associated control is required to be a descendant of a form , let alone one that is to be submitted. label及其关联控件都不需要是form的后代,更不用说要提交的form了。

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

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