HTML元素 - form

来源:互联网 时间:1970-01-01

定义

说明所包含的控件是某个表单的组成部分。

Specifies that the contained controls take part in a form.

注释

安全性警告:错误地使用该对象可能危及你应用程序的安全。通过表单传递的数据使用HTTP协议,该协议没有经过加密,所以很有可能在传递中,数据被他人读取或篡改。安全超文本传输协议 (HTTPS) 可以提供安全的数据传送。

表单允许客户端的用户以标准格式向服务器提交数据。表单的创建者为了收集所需数据,使用了各种控件设计表单,如 INPUT 或 SELECT。查看表单的用户只需填写数据并单击提交按钮即可向服务器发送数据。服务器上的脚本会处理这些数据。

如果控件元素中的数据要随表单一起发送出去的话,那么必须定义每个控件元素的 NAME 标签属性。要引用表单中的元素,可使用元素的 name 属性或 id 属性,或通过 elements 集合引用。

如果焦点位于表单中的某个控件时而用户按了 ESC 键,该控件的值将会恢复到上次的值。如果用户再次按 ESC 键,整个表单都会重置。如果焦点位于表单中但并不在某个控件时用户按了 ESC 键,整个表单都会重置。

如果表单仅包含一个文本框时用户按下回车键,会触发onsubmit 事件。如果表单有 INPUT type=submit 元素,该元素将显示成带有黑色边框的按钮,表示用户按下回车键即可提交表单。

此元素在 Internet Explorer 3.0 及以上版本的 HTML 和脚本中可用。

此元素是块元素。

此元素需要关闭标签。

Security Alert Using this object incorrectly can compromise the security of your application. Data submitted through a form using the HTTP protocol is not encrypted and can be read and possibly tampered with in transmission. The Secure Hypertext Transfer Protocol (HTTPS) can provide more secure data transmission.

Forms enable client-side users to submit data to a server in a standardized format. The creator of a form designs the form to collect the required data using a variety of controls, such as INPUT or SELECT. Users viewing the form fill in the data and then click the Submit button to send the data to the server. A script on the server then processes the data.

Each control element's NAME attribute must be defined if the data is to be submitted with the form. An element in a form can be referenced by the name property or the id property, or through the elements collection.

When the focus is on a control in a form and the user presses ESC, the value of the control reverts to the last value. The form resets if the user presses ESC again. If the focus is on the form but not on a particular control and the user presses ESC once, the form resets.

If the form includes only one text box and the user presses ENTER, the onsubmit event fires. If the form has an INPUT type=submit element, it will appear as a button with a dark border, which indicates the user can press ENTER to submit the form.

This element is available in HTML and script as of Internet Explorer 3.0.

This element is a block element.

This element requires a closing tag.

示例代码

下面的例子使用 FORM 元素创建了一个简单的表单,其中包含一个用于输入用户姓名的文本框和用于选择喜爱冰淇淋口味的选择框。当用户单击提交按钮时,表单将把数据发送到 ACTION 标签属性列出的 URL。METHOD 标签属性的值决定了将服务器发送到服务器的方式。

This example uses the FORM element to create a basic form containing a text entry box for the user's name and a select control for choosing a favorite ice cream flavor. When the user clicks the Submit button, the form sends the data to the URL listed in the ACTION attribute. The value of the METHOD attribute determines how to send the data to the server.

<HTML>

<FORM ACTION="http://example.microsoft.com/sample.asp" METHOD="POST">

输入你的姓名: <INPUT NAME="FName"><BR>

你最喜欢的冰淇淋口味:

<SELECT NAME="Flavor">

<OPTION VALUE="Chocolate">巧克力

<OPTION VALUE="Strawberry">草莓

<OPTION VALUE="Vanilla" SELECTED>香草

</SELECT>

<P><INPUT TYPE=SUBMIT>

</FORM>

</HTML>




相关阅读:
Top