当前位置: 首页 > 网络学院 > 网页制作基础教程 > HTML > HTML <form>标签

HTML
HTML Head
HTML Meta
HTML URLs
HTML Scripts
HTML 属性
HTML 事件
HTML URL-encode
HTML Web服务器
HTML 摘要
HTML 实例
标签列表
标准属性
事件属性
ASCII码
特殊字符
HTTP状态消息

HTML <form>标签


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 419 ::
收藏到网摘: n/a

定义与用法

The form element creates a form for user input. A form can contain textfields, checkboxes, radio-buttons and more. Forms are used to pass user-data to a specified URL.
form元素可建立针对用户输入的表单。表单中可以包含文字输入,复选框,单选按钮以及更多一些。表单可以将用户数据发送到指定的URL。


在HTML和XHTML中的区别

NONE


实例

代码 输出
<form action="form_action.asp"
method="get">

First name:
<input type="text" name="fname" value="Mickey" />
<br />
Last name:
<input type="text" name="lname" value="Mouse" />
<br />
<input type="submit" value="Submit" />

</form>

<p>
If you click the "Submit" button, you will send your input to a new page called form_action.asp.<br />
当你按了Submit,你会到达一个新的页面(form_action.asp),上面会有你输入的信息
</p>
First name:
Last name:

If you click the "Submit" button, you will send your input to a new page called form_action.asp.
当你按了Submit,你会到达一个新的页面(form_action.asp),上面会有你输入的信息



必选属性

DTD indicates in which DTD the attribute is allowed. S=Strict, T=Transitional, and F=Frameset.
下表中的DTD列指明了被支持的DTD属性。S=Strict(精确的),T=Transitional(传统的),F=Frameset(框架)

属性 Value 描述 DTD
action URL A URL that defines where to send the data when the submit button is pushed
定义当按下提交后将信息数据发送到的页面URL
STF

可选属性

属性 Value 描述 DTD
accept list of contenttypes A comma separated list of content types that the server that processes this form will handle correctly
用逗号分隔内容类型以便服务器能更准确的处理表单
STF
accept-charset charset_list A comma separated list of possible character sets for the form data. The default value is "unknown"
用逗号分隔表单数据中可能出现的字符类型。默认的值为"未知"
STF
enctype mimetype The mime type used to encode the content of the form
使用mime类型可以将表单内容进行加密。
STF
method get
post
The HTTP method for sending data to the action URL. Default is get.
HTTP发送数据的方式。默认为get

method="get": This method sends the form contents in the URL:
URL?name=value&name=value. Note: If the form values contains non-ASCII characters or exceeds 100 characters you MUST use method="post".
该发送方式会将信息显示在URL地址中。注意:如果表单中的值含有非ASCII字符或是超过了100个字符,那么你必须使用method="post"

method="post": This method sends the form contents in the body of the request. Note: Most browsers are unable to bookmark post requests.
该方法会将表单发送到请求页的主体上。注意:大多数浏览器不能将发送的请求页面设置为书签。

STF
name form_name Defines a unique name for the form
给表单定义唯一的name
TF
target _blank
_self
_parent
_top

Where to open the target URL.
如何打开目标URL

  • _blank - 在新窗口打开目标URL
  • _self - 在自身窗口或是框架里打开目标URL
  • _parent - 目标URL将在父级框架中打开
  • _top - 目标URL将在窗口的主体中打开
TF

标准属性

id, class, title, style, dir, lang, xml:lang

For a full description, go to Standard Attributes.
查看完整的属性

事件属性

onsubmit, onreset, onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup

For a full description, go to Event Attributes.
查看完整的属性


尝试与演示

Form with input fields and a submit button
How to add a form to a page. The form contains two input fields and a submit button.
如何为页面加入表单。表单包含两个输入框和一个提交按钮

Form with checkboxes
This form contains two checkboxes, and a submit button.
包含两个复选框以及一个提交按钮的表单

Form with radiobuttons
This form contains two radio buttons, and a submit button.
包含两个单选按钮以及一个提交按钮的表单

Send e-mail from a form
How to send e-mail from a form.
用表单发送电子邮件

评论 (0) All

登陆 | 还没注册?