错误消息:< span> vs< label> [英] Error Message: <span> vs <label>
问题描述
当您在HTML中显示错误消息时,您使用了哪个元素,< span>
或 < label>
?
When you display an error message in HTML, which element do you use, <span>
or <label>
?
你可以列出每个人的一些优点和缺点,假设一些样式,例如颜色和边距通过他们的类
?
Can you list some pros and cons for each of them, assuming that some styling, such as color and margin will be applied through their class
?
应用
Thanks!
推荐答案
假设您的意思是与特定表单控件关联的错误消息,请使用< label>
。
Assuming you mean an error message associated with a specific form control, use a <label>
.
语义参数有争议,因为在这种情况下它们并不明确,但实际的参数非常好。如果屏幕阅读器处于表单模式,则可能跳过非标签文本隐藏用户的错误信息。
The semantic arguments are subject to debate, as they aren't clear cut in this case, but the practical arguments win quite nicely. If a screen reader is in forms mode, it may skip over non-label text thus hiding the error messages from the user.
这篇关于错误消息:< span> vs< label>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!