为什么使用HTML表单而不是表格的定义列表(DL,DD,DT)标记? [英] Why use definition lists (DL,DD,DT) tags for HTML forms instead of tables?

查看:260
本文介绍了为什么使用HTML表单而不是表格的定义列表(DL,DD,DT)标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近遇到了一些例子:

  dl> 
< dt>全名:< / dt>
< dd>< input type =textname =fullname>< / dd>
< dt>电子邮件地址:< / dt>
< dd>< input type =textname =email>< / dd>
< / dl>

。这是为什么?使用表的优点是什么?

解决方案

我想由你来决定语义,但在我看来: / p>

而不是定义列表,应使用与表单相关的属性。

 < form> 
< label for =fullname>全名:< / label>
< input type =textname =fullnameid =fullname>
< label for =email>电子邮件地址:< / label>
< input type =textname =emailid =email>
< / form>

< label&标签应当引用< input>标签的id属性。标签。请注意,当标签与字段相关联时,点击标签会将相关字段置于焦点。



您还可以使用标签,如< fieldset>以将表单的部分聚集在一起,< legend>为字段集添加标题。


I've come across a few examples recently that do things like:

<dl>
  <dt>Full Name:</dt>
  <dd><input type="text" name="fullname"></dd>
  <dt>Email Address:</dt>
  <dd><input type="text" name="email"></dd>
</dl>

for doing HTML forms. Why is that? What is the advantage over using tables?

解决方案

I guess it's up to you to determine the semantics, but in my opinion:

Rather than a definition list, form-related properties should be used.

<form>
  <label for="fullname">Full Name:</label>
  <input type="text" name="fullname" id="fullname">
  <label for="email">Email Address:</label>
  <input type="text" name="email" id="email">
</form>

The "for" attribute in the <label> tag should reference the "id" attribute of a <input> tag. Note that when labels are associated with fields, clicking the label will put the associated field in focus.

You can also use tags like <fieldset> to cluster sections of a form together and <legend> to caption a fieldset.

这篇关于为什么使用HTML表单而不是表格的定义列表(DL,DD,DT)标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆