search
HomeWeb Front-endHTML Tutorial第 10 章 表单元素[上]_html/css_WEB-ITnose

学习要点:

1.表单元素总汇

2.表单元素解析

 

主讲教师:李炎恢

 

本章主要探讨 HTML5 中表单元素,表单元素用于获取用户的输入数据。

 

一.表单元素总汇

在 HTML5 的表单中,提供了各种可供用户输入的表单控件。

 

元素名称

说明

form

表示 HTML 表单

input

表示用来收集用户输入数据的控件

textarea

表示可以输入多行文本的控件

select

表示用来提供一组固定的选项

option

表示提供提供一个选项

optgroup

表示一组相关的 option 元素

button

表示可用来提交或重置的表单按钮(或一般按钮)

datalist

定义一组提供给用户的建议值

fieldset

表示一组表单元素

legend

表示 fieldset 元素的说明性标签

label

表示表单元素的说明标签

output

表示计算结果

 

二.表单元素解析

1.

定义表单

<form method="post" action="http://www.haosou.com/"> <br />  <button>提交</button></form>

解释:

元素主要是定义本身是一组表单。

 

元素名称

说明

action 

表示表单提交的页面

method

表示表单的请求方式:有 POST 和 GET 两种,默认 GET

enctype

表示浏览器对发送给服务器的数据所采用的编码格式。有三种:application/x-www-form-urlencoded(默认编码,不能将文件上传到服务器)、multipart/form-data(用于上传文件到服务器)、text/plain(未规范的编码,不建议使用,不同浏览器理解不同)

name

设置表单名称,以便程序调用

target

设置提交时的目标位置:_blank、_parent、_self、_top

autocomplete

设置浏览器记住用户输入的数据,实现自动完成表单。默认为 on 自动完成,如果不想自动完成则设置 off。

novalidate

设置是否执行客户端数据有效性检查,后面课程讲解。

 

//使用 get 提交数据

method="get"

 

//丧失自动提示功能

autocomplete="off"

 

//使用_blank 新建目标 

target="_blank"

 

2.表示用户输入数据

<input name="user">

解释:元素默认情况会出现一个单行文本框,有五个属性。

 

属性名称

说明

autofocus

让光标聚焦在某个 input 元素上,让用户直接输入

disabled

禁用 input 元素

autocomplete

单独设置 input 元素的自动完成功能

form

让表单外的元素和指定的表单挂钩提交

type

input 元素的类型,内容较多,将在下节课展开讲解

name

定义 input 元素的名称,以便接收到相应的值

 

//聚焦光标

<input name="user" autofocus>

 

//禁用 input

<input name="user" disabled>

 

//禁止自动完成

 

//表单外的 input 

...

 

3.添加说明标签

<p><label for="user">用户名:<input id="user" name="user"></label></p>

解释:

 

4.

对表单进行编组

<fieldset>...</fieldset>

解释:

元素可以将一些表单元素组织在一起,形成一个整体。

 

属性名称

说明

name

给分组定义一个名称

form

让表单外的分组与表单挂钩

disabled

禁用分组内的表单

 

5.添加分组说明标签

<fieldset>    <legend>        注册表单    </legend></fieldset>

解释:元素给分组加上一个标题。

 

6.添加按钮 

<button type="submit"></button>

解释:

值名称

说明

submit

表示按钮的作用是提交表单,默认

reset

表示按钮的作用是重置表单

button

表示按钮为一般性按钮,没有任何作用

 

//提交表单 

<button type="submit">提交</button>

 

//重置表单

<button type="reset">重置</button> 

 

//普通按钮

<button type="button">按钮</button> 

 

对于 type 属性为 submit 时,按钮还会提供额外的属性。

属性名称

说明

form

指定按钮关联的表单

formaction

覆盖 form 元素的 action 属性

formenctype

覆盖 form 元素的 enctype 属性

formmethod

覆盖 form 元素的 method 属性

formtarget

覆盖 form 元素的 target 属性

formnovalidate

覆盖 form 元素的 novalidate 属性

 //表单外关联提交

<button type="submit" form="register">提交</button>

 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
HTML as a Markup Language: Its Function and PurposeHTML as a Markup Language: Its Function and PurposeApr 22, 2025 am 12:02 AM

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools