Home > Web Front-end > H5 Tutorial > Forms in HTML5

Forms in HTML5

高洛峰
Release: 2017-02-06 14:11:23
Original
1356 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 the area separated by commas, but Firefox does not support it. The element also has some new features.

list: The ID of the element, 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 the element 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

The element displays a column of

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

element

element represents the result of the calculation.

You can use the for attribute to associate the element 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 the element. 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 the and