Forms in HTML5

高洛峰
Release: 2017-02-06 14:11:23
Original
1205 people have browsed it

Compared with HTML4, the elements and features in HTML5 provide a greater degree of semantic markup, and also remove a large number of redundant elements that exist in HTML4 due to scripts and styles. By making forms behave more consistently on different websites and responding to user input data in a timely manner, HTML5 form features provide users with a better experience. These experiences also apply to users who have disabled browser scripting.

This topic describes some new features or changes that are supported by Gecko/Firefox4 or higher.

The type attribute of element

has more values.

search: This element renders a search box. Newlines are removed from the input value, but there are no other syntax enhancements.

tel: This element can be used as an input control for editing phone numbers. Newlines are removed from the input value, and no other syntax enhancements are made because phone number internationalization differences are very obvious. You can use properties such as pattern and maxlength to limit the values entered into the control.

url: This element is rendered as an input control for editing a URL. Newlines and leading and trailing spaces will be automatically removed.

email: This element is rendered as an email address. Line breaks are automatically removed. It is possible to set an invalid email address, but if it meets the constraints of the input box, it must comply with the specifications in Extended Backus Normal Form (ABNF): 1( atext / "." ) "@" ldh-str 1( "." ldh-str ) where atext is defined in RFC 5322 section 3.2.3 and ldh-str is defined in RFC 1034 section 3.5. .

Note: If the multiple attribute is set, multiple emails can be entered in thearea separated by commas, but Firefox does not support it. Theelement also has some new features.

list: The ID of theelement, the content of the element, and the

pattern: A regular expression used to check the value of a control, which can be applied to input elements whose type values are text, tel, search, url, and email.

form: A string indicating which

element this input belongs to. An input can only exist in one form.

formmethod: A string indicating which HTTP method (GET or POST) will be used when the form is submitted; if defined, the method attribute on theelement can be overridden. formmethod can only take effect when the type value is image or submit and the form attribute is set.

x-moz-errormessage: A string that displays an error message when form field validation fails. This value is a Mozilla extension and is not a standard. The

element

element has a new attribute:

novalidate: Setting this attribute will not validate the form before it is submitted. .

Element

Theelement displays a column of

You can use the list attribute on theelement to associate a specific input with a specificelement. The

element

element represents the result of the calculation.

You can use the for attribute to associate theelement with other elements in the document that can affect the operation (for example, input or parameters). The value of the for attribute is a space-separated list of IDs of other elements.

Gecko 2.0 (not the case for other browsers) supports customizing validity constraints and error messages for theelement. You can use the following CSS pseudo-classes for it: :invalid, :valid, :-moz-ui-invalid, and :-moz-ui-valid. This can be useful in situations where the calculation result violates a business rule, but is not due to an error in a specific input value (for example, "the total percentage cannot exceed 100").

placeholder attribute

The placeholder attribute acts on theand

autofocus attribute

The autofocus attribute allows you to specify a form control that automatically gets focus when the page loads unless the user overrides it, such as by entering a value into another control. Only one form within a document can have the autofocus attribute, which is a Boolean value. This attribute applies to,

Related labels:
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!