定位表单元素
Unfortunately when the HTML was being designed for forms consistency was not a high priority. You will find that most form-specific tags are <input>
tags, but there are several notable exceptions.
不幸的是,在设计HTML以实现表单一致性时,它并不是一个高优先级。 您会发现大多数特定于表单的标记是<input>
标记,但是有几个值得注意的例外。
The main points to remember about forms are as follows:
关于表格要记住的要点如下:
a form starts with a
<form>
tag and closes with a matching</form>
tag. Form elements (text fields, drop-down menus, etc) can be placed anywhere on the page, with or without a surroundingform
tag.表单以
<form>
标记开始,并以匹配的</form>
标记结束。 表单元素(文本字段,下拉菜单等)可以放置在页面上的任何位置,带有或不带有周围的form
标签。The
form
tag has two attributes that are typically added:method
andaction
.form
标记具有两个通常添加的属性:method
和action
。A form’s
method
is the way the submitted data is passed to whatever will be processing it (a CGI script, a PHP script, etc). Often, this method will bepost
. Alternatively, theget
method appends the data to the URL itself when it is submitted, which is obviously less secure (but helpful, if you are interested in debugging a form or bookmarking a page created through a form decision).表单的
method
是将提交的数据传递到将要处理它的对象(CGI脚本, PHP脚本等)的方式。 通常,此方法将是post
。 另外,get
方法在提交数据时会将数据附加到URL本身,这显然不太安全(但是,如果您有兴趣调试表单或为通过表单决策创建的页面添加书签,则很有用)。The
action
attribute of the form tag tells the form where to submit its data to. If a CGI script written in Perl was processing the data, theaction
attribute would typically be set to something like cgi-bin/form.pl. If a PHP script, it would be something like formhandler.php.form标签的
action
属性告诉表单将数据提交到哪里。 如果用Perl编写的CGI脚本正在处理数据,则通常将action
属性设置为cgi-bin / form.pl之类的内容 。 如果是PHP脚本,则类似于formhandler.php 。
The first step in creating our form is the opening and closing <form>
tags, with the correct attributes:
创建表单的第一步是打开和关闭具有正确属性的<form>
标记:
<form method="post" action="formhandler.php">
</form>
fieldset
is a container element inside the form. Think of filling out your tax form at the end of each year: each major section of the form (personal information, employer, income) is divided into a seperate box. fieldset
is that box in the context of a form. A form may contain multiple fieldset
s.
fieldset
是表单内的容器元素。 考虑在每年年底填写税表:该表的每个主要部分(个人信息,雇主,收入)都分为一个单独的框。 fieldset
是表单上下文中的那个框。 一个表单可以包含多个fieldset
。
Immediately inside the fieldset
you should enter a <legend>
tag, with appropriate content. The <legend>
is essentially the label for the entire fieldset
, and typically indicates the purpose of that section. (“Personal information”, “Mailing Address”, “Billing Info”, etc).
在fieldset
立即输入一个<legend>
标记,其中包含适当的内容。 <legend>
本质上是整个fieldset
的标签,通常指示该部分的目的。 (“个人信息”,“邮寄地址”,“账单信息”等)。
The complete setup code for a form is therefore:
因此,表单的完整设置代码为:
<form method="post" action="formhandler.php">
<fieldset>
<legend>Legend for form</legend>
<!-- form content goes here -->
</fieldset>
</form>
fieldset
and legend
are optional, but they are useful elements.
fieldset
和legend
是可选的,但它们是有用的元素。
定位表单元素