search
HomeWeb Front-endH5 TutorialHTML5 HTML element extension (Part 2) - the enhanced Form element deserves attention_html5 tutorial skills

Among the HTML5 enhanced elements, the most noteworthy is the form element. In HTML5, forms have been significantly revamped, and some functions that previously required JavaScript coding can now be easily implemented without coding. Before we start the discussion, something needs to be noted:

In HTML5, form controls can be outside one or more forms to which they belong. Therefore, form controls such as fieldset, label, and input have added the form attribute to identify the form to which the form control belongs.

in HTML5 :

1. The form element itself adds two new attributes: autocomplete and novalidate. The autocomplete attribute is used to enable the "drop-down suggestion list" function, and the novalidate attribute is used to turn off the form validation function, which can be useful during testing.

2. The fieldset element adds three new attributes: disable, name and form. The disable attribute is used to disable the fieldset, the name attribute is used to set the name of the fieldset, and the value of the form attribute is the ID of one or more forms to which the fieldset belongs. As mentioned earlier, when the fieldset is placed outside the form, you must Set the form attribute of the fieldset tag so that the fieldset can be correctly associated with one or more forms.

3. In addition to the for attribute, the label element only adds the form attribute. What’s worth mentioning here is the for attribute, which I haven’t really noticed before. The for attribute is used to specify the form control attached to the label, so that when the label is clicked, the attached form control will gain focus, for example:

Copy code
The code is as follows:


> ;

Click "Click Me", and the following input box will gain focus.

4. The input element introduces some new types and attributes to enhance the usability of the form. These new input types are very useful for organizing and categorizing data, but unfortunately no browser supports all of them well.
In addition to the original button, text, submit, checkbox, radio, select, password types, HTML5 has added the following new input types:

Color: color
Various dates: date, datetime, datetime-local, month, week, time
Email: email
Number: number
Range: range
Search: search
Telephone: tel
URL type: url

You can run the following example to check the support of different browsers:

Copy the code
The code is as follows:


Select your favorite color:
Birthday: < ;input type="date" name="bday" />
Birthday (date and time):
Birthday (date and time) :
Birthday (month and year):
Select a time:
Select a week:
Quantity (between 1 and 5 ):
Quantity(between 1 and 10):
Search Google:
Telephone:
Add your homepage:
E-mail:



The following are the newly added input attributes:
autocomplete: Automatically display previously entered information, taking the value "on" or "off". Applicable to text, search, url, tel, email, password, datepickers, range, and color types.

autofocus: Automatically obtains focus after the page is loaded.
form: Specify the form to which the input belongs, which can be multiple.
formaction: Specify the page (URL) or file to process this input after the form is submitted. ​
formenctype: Specify how to encode the data after the form is submitted.
formmethod: Specifies the HTTP method for sending form data, which will override the HTTP method of the corresponding form.
formnovalidate: Does not check the validity of data before submission.
formtarget: Specify where to display the response content after the form is submitted.
height, width: input box length and width, only applicable to image type. ​
max, min: The maximum and minimum values ​​of the input value. Suitable for meaningful number, range, and date types. ​
multiple: Whether to allow multiple values ​​to be entered, applicable to email and file types.
pattern: Specifies the regular expression to verify the input value, suitable for text, search, url, tel, email, password.
placeholder: Prompt information before input, applicable to text, search, url, tel, email, password.
required: Whether it is a required item. If the required item is not filled in, the form cannot be submitted. Applicable to text, search, url, tel, email, password, date pickers, number, checkbox, radio, and file types.
step: Enter the step value for automatic growth, applicable to number, range, date, datetime, datetime-local, month, time and week types.
list: A candidate list of input items, which needs to be used in conjunction with the datalist element. The list attribute can be used on these types: text, search, url, tel, email, date, number, range and color. Visual inspection works on FireFox. Look at a small example:

Copy the code
The code is as follows:


Favorites






The following example attempts to use each Properties, you can run it in different browsers to see the actual effect:

Copy the code
The code is as follows:


E-mail:
Image:
Enter a date before 1980-01-01:
Enter a date after 2000-01-01:
Quantity (between 1 and 5):
Select images:
Country code:
First Name:
Username:
Number:









First name:


Last name:

建议:虽然并不是所有的浏览器都支持全部的类型,但是还是鼓励大家使用这些新类型,因为即使浏览器不支持,只不过是会退化成简单的text输入框而已。

实用参考:
W3C的教程:http://www.w3schools.com/html5/default.asp
HTML5官方指导:http://dev.w3.org/html5/html-author/
相当不错的一个指导网站:http://html5doctor.com/
HTML5中文教程:http://www.html5china.com/
一个不错的前端博客:http://www.pjhome.net/default.asp?cateID=1
JS操作表单的相关知识:http://www.cnblogs.com/xugang/archive/2010/08/12/1798005.html

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
Mastering Microdata: A Step-by-Step Guide for HTML5Mastering Microdata: A Step-by-Step Guide for HTML5May 14, 2025 am 12:07 AM

MicrodatainHTML5enhancesSEOanduserexperiencebyprovidingstructureddatatosearchengines.1)Useitemscope,itemtype,anditempropattributestomarkupcontentlikeproductsorevents.2)TestmicrodatawithtoolslikeGoogle'sStructuredDataTestingTool.3)ConsiderusingJSON-LD

What's New in HTML5 Forms? Exploring the New Input TypesWhat's New in HTML5 Forms? Exploring the New Input TypesMay 13, 2025 pm 03:45 PM

HTML5introducesnewinputtypesthatenhanceuserexperience,simplifydevelopment,andimproveaccessibility.1)automaticallyvalidatesemailformat.2)optimizesformobilewithanumerickeypad.3)andsimplifydateandtimeinputs,reducingtheneedforcustomsolutions.

Understanding H5: The Meaning and SignificanceUnderstanding H5: The Meaning and SignificanceMay 11, 2025 am 12:19 AM

H5 is HTML5, the fifth version of HTML. HTML5 improves the expressiveness and interactivity of web pages, introduces new features such as semantic tags, multimedia support, offline storage and Canvas drawing, and promotes the development of Web technology.

H5: Accessibility and Web Standards ComplianceH5: Accessibility and Web Standards ComplianceMay 10, 2025 am 12:21 AM

Accessibility and compliance with network standards are essential to the website. 1) Accessibility ensures that all users have equal access to the website, 2) Network standards follow to improve accessibility and consistency of the website, 3) Accessibility requires the use of semantic HTML, keyboard navigation, color contrast and alternative text, 4) Following these principles is not only a moral and legal requirement, but also amplifying user base.

What is the H5 tag in HTML?What is the H5 tag in HTML?May 09, 2025 am 12:11 AM

The H5 tag in HTML is a fifth-level title that is used to tag smaller titles or sub-titles. 1) The H5 tag helps refine content hierarchy and improve readability and SEO. 2) Combined with CSS, you can customize the style to enhance the visual effect. 3) Use H5 tags reasonably to avoid abuse and ensure the logical content structure.

H5 Code: A Beginner's Guide to Web StructureH5 Code: A Beginner's Guide to Web StructureMay 08, 2025 am 12:15 AM

The methods of building a website in HTML5 include: 1. Use semantic tags to define the web page structure, such as, , etc.; 2. Embed multimedia content, use and tags; 3. Apply advanced functions such as form verification and local storage. Through these steps, you can create a modern web page with clear structure and rich features.

H5 Code Structure: Organizing Content for ReadabilityH5 Code Structure: Organizing Content for ReadabilityMay 07, 2025 am 12:06 AM

A reasonable H5 code structure allows the page to stand out among a lot of content. 1) Use semantic labels such as, etc. to organize content to make the structure clear. 2) Control the rendering effect of pages on different devices through CSS layout such as Flexbox or Grid. 3) Implement responsive design to ensure that the page adapts to different screen sizes.

H5 vs. Older HTML Versions: A ComparisonH5 vs. Older HTML Versions: A ComparisonMay 06, 2025 am 12:09 AM

The main differences between HTML5 (H5) and older versions of HTML include: 1) H5 introduces semantic tags, 2) supports multimedia content, and 3) provides offline storage functions. H5 enhances the functionality and expressiveness of web pages through new tags and APIs, such as and tags, improving user experience and SEO effects, but need to pay attention to compatibility issues.

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 Article

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.