例如.这是简单的形式(我经常使用):
但我读了一些书,看到我的一些朋友经常这样做:
不同之处在于:它们经常将所有组件包装在div标签内,然后为其分配一个类名(尽管div标签内部只有一个组件).我不知道他们这样做有什么好处.
谢谢 :)
最佳答案
WHATWG: 4.10.1.1 Writing a form’s user interface
Any form starts with a form
element,inside which are placed the controls. Most controls are represented by the input
element,which by default provides a text control. To label a control,the label
element is used; the label text and the control itself go inside the label
element. Each part of a form is considered a paragraph,and is typically separated from other parts using p
elements. Putting this together,here is how one might ask for the customer’s name:
WAI: Forms > Grouping Controls
Grouping related form controls makes forms more understandable for all users,as related controls are easier to identify… In this example,the div
element has role=group
to indicate that the contained elements are members of a group and the aria-labelledby
attribute references the id for text that will serve as the label for the group…
它还建议使用< fieldset>和< legend>元素. <字段集> element为相关的表单控件提供了一个容器,< legend> element用作标识组的标题.
除此之外,样式和操作是许多开发人员的主要原因.