Home Web Front-end H5 Tutorial HTML5 HTML element extension (Part 2) - the enhanced Form element deserves attention_html5 tutorial skills

HTML5 HTML element extension (Part 2) - the enhanced Form element deserves attention_html5 tutorial skills

May 16, 2016 pm 03:49 PM
form form

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 of this Website
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

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

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1270
29
C# Tutorial
1249
24
How to implement page jump after PHP form submission How to implement page jump after PHP form submission Aug 12, 2023 am 11:30 AM

How to implement page jump after PHP form submission [Introduction] In web development, form submission is a common functional requirement. After the user fills out the form and clicks the submit button, the form data usually needs to be sent to the server for processing, and the user is redirected to another page after processing. This article will introduce how to use PHP to implement page jump after form submission. [Step 1: HTML Form] First, we need to write a page containing a form in an HTML page so that users can fill in the data that needs to be submitted.

How to use JavaScript to realize the automatic prompt function of the input box content of the form? How to use JavaScript to realize the automatic prompt function of the input box content of the form? Oct 20, 2023 pm 04:01 PM

How to use JavaScript to realize the automatic prompt function of the input box content of the form? Introduction: The automatic prompt function of the form input box content is very common in web applications. It can help users quickly enter the correct content. This article will introduce how to use JavaScript to achieve this function and provide specific code examples. Create the HTML structure First, we need to create an HTML structure that contains the input box and the auto-suggestion list. You can use the following code: &lt;!DOCTYP

How to handle user rights management in PHP forms How to handle user rights management in PHP forms Aug 10, 2023 pm 01:06 PM

How to handle user rights management in PHP forms With the continuous development of web applications, user rights management is one of the important functions. User rights management can control users' operating rights in applications and ensure the security and legality of data. In PHP forms, user rights management can be implemented through some simple code. This article will introduce how to handle user rights management in PHP forms and give corresponding code examples. 1. Definition and management of user roles First of all, defining and managing user roles is a matter of user rights.

How to use JavaScript to implement real-time verification of the input box content of a form? How to use JavaScript to implement real-time verification of the input box content of a form? Oct 18, 2023 am 08:47 AM

How to use JavaScript to implement real-time verification of the input box content of a form? In many web applications, forms are the most common way of interaction between users and the system. However, the content entered by the user often needs to be validated to ensure the accuracy and completeness of the data. In this article, we will learn how to use JavaScript to implement real-time verification of the content of the form's input box and provide specific code examples. Creating the form First we need to create a simple table in HTML

How to use HTML, CSS and jQuery to realize the advanced function of automatic saving of forms How to use HTML, CSS and jQuery to realize the advanced function of automatic saving of forms Oct 28, 2023 am 08:20 AM

How to use HTML, CSS and jQuery to implement the advanced function of automatic saving of forms. Forms are one of the most common elements in modern web applications. When users enter form data, how to implement the automatic saving function can not only improve the user experience, but also ensure data security. This article will introduce how to use HTML, CSS and jQuery to implement the automatic saving function of the form, and attach specific code examples. 1. Structure of HTML form. Let’s first create a simple HTML form.

PHP form processing: form data query and filtering PHP form processing: form data query and filtering Aug 07, 2023 pm 06:17 PM

PHP form processing: form data query and filtering Introduction In Web development, forms are an important way of interaction. Users can submit data to the server through forms for further processing. This article will introduce how to use PHP to process the query and filter functions of form data. Form design and submission First, we need to design a form that includes query and filter functions. Common form elements include input boxes, drop-down lists, radio buttons, check boxes, etc., which can be designed according to specific needs. When the user submits the form, the data will be sent to POS

How to set up a secure HTTPS connection for a PHP form? How to set up a secure HTTPS connection for a PHP form? Aug 17, 2023 pm 03:25 PM

How to set up a secure HTTPS connection for a PHP form? As the Internet develops, security becomes more and more important in web development. The encrypted transmission protocol HTTPS plays a key role in protecting data transmission. When using PHP forms for data transmission, we can take some measures to ensure the security of the connection. This article will guide you on how to set up a secure HTTPS connection for PHP forms, with some code examples. Purchase an SSL Certificate First, you need to purchase an SSL Certificate. SSL certificate is a guaranteed website

Java implements real-time verification and prompting functions of forms Java implements real-time verification and prompting functions of forms Aug 07, 2023 am 10:42 AM

Java implements real-time verification and prompting functions of forms. With the popularity and development of network applications, the use of forms has become more and more important. A form is an element in a web page that is used to collect and submit user data, such as a form on a registration or login page. When users fill out forms, they often need to verify and prompt the data they enter to ensure the correctness and completeness of the data. In this article, we will introduce how to use Java language to implement real-time verification and prompt functions of forms. To build an HTML form, first of all, we need to use the HTML language

See all articles