HTML5 new form attributes
HTML5's
novalidate attribute specifies that the form or input fields should not be validated when submitting the form.
Example
No need to verify submitted form data
autofocus attribute
The autofocus attribute is a boolean attribute. The
autofocus attribute specifies that the field automatically gains focus when the page is loaded.
Example
Let the "First name" input field automatically focus when the page loads:
form attribute
The form attribute specifies one or more forms to which the input field belongs.
Tip: If you need to reference more than one form, use a space-separated list.
Instance
The input field located outside the form refers to the HTML form (the input form is still part of the form):
formaction attribute
The formaction attribute is used to describe the URL address of form submission.
The formaction attribute will override the action attribute in the
formenctype 属性
formenctype 属性描述了表单提交到服务器的数据编码 (只对form表单中 method="post" 表单)
formenctype 属性覆盖 form 元素的 enctype 属性。
主要: 该属性与 type="submit" 和 type="image" 配合使用。
实例
第一个提交按钮已默认编码发送表单数据,第二个提交按钮以 "multipart/form-data" 编码格式发送表单数据:
formmethod 属性
formmethod 属性定义了表单提交的方式。
formmethod 属性覆盖了
formnovalidate 属性
novalidate 属性是一个 boolean 属性.
novalidate属性描述了 元素在表单提交时无需被验证。
formnovalidate 属性会覆盖
formtarget 属性
formtarget 属性指定一个名称或一个关键字来指明表单提交数据接收后的展示。
The formtarget 属性覆盖
height 和 width 属性
height 和 width 属性规定用于 image 类型的 标签的图像高度和宽度。
注意: height 和 width 属性只适用于 image 类型的 标签。
提示:图像通常会同时指定高度和宽度属性。如果图像设置高度和宽度,图像所需的空间 在加载页时会被保留。如果没有这些属性, 浏览器不知道图像的大小,并不能预留 适当的空间。图片在加载过程中会使页面布局效果改变 (尽管图片已加载)。
实例
定义了一个图像提交按钮, 使用了 height 和 width 属性:
list 属性
list 属性规定输入域的 datalist。datalist 是输入域的选项列表。
OperaSafariChromeFirefoxInternet Explorer
实例
在
min 和 max 属性
min、max 和 step 属性用于为包含数字或日期的 input 类型规定限定(约束)。
注意: min、max 和 step 属性适用于以下类型的 标签:date pickers、number 以及 range。
实例
multiple attribute
The multiple attribute is a boolean attribute. The
multiple attribute specifies that multiple values can be selected in the element.
Note: The multiple attribute applies to the following types of tags: email and file. : email, and file.
Example
Upload multiple files:
pattern attribute
The pattern attribute describes a regular expression used to validate the value of the element.
Note: The pattern attribute applies to the following types of tags: text, search, url, tel, email, and password.
Tip: It is used with the global title attribute to describe the pattern.
Example
The following example shows a text field that can only contain three letters (excluding numbers and special characters):
placeholder attribute
The placeholder attribute provides a hint describing the expected value of the input field.
A brief prompt is displayed on the input field before the user enters a value.
Note: The placeholder attribute applies to the following types of tags: text, search, url, telephone, email and password.
Example
input field prompt text t:
required attribute
required attribute is a boolean attribute.
required attribute specifies that the input field must be filled in before submission (cannot be empty).
Note: The required attribute applies to the following types of tags: text, search, url, telephone, email, password, date pickers, number, checkbox, radio and file.
Instance
Input field that cannot be empty:
step attribute
The step attribute specifies the legal number interval for the input field.
If step="3", the legal numbers are -3, 0, 3, 6, etc.
Tip: The step attribute can be used with the max and min attributes to create a range value.
Note: The step attribute is the same as The following types are used together: number, range, date, datetime, datetime-local, month, time and week.
Instance
specifies that the input step is 3:
HTML5 also introduces a new element
You can also use the for attribute to specify the relationship between the output element and other elements in the document that affect the calculation (for example, as an input source or parameter). The value of the for attribute is a space-separated list of IDs of other elements.
placeholder attribute
HTML5 introduces a new attribute called placeholder. This attribute on the and
This attribute is only supported by the latest versions of Mozilla, Safari and Chrome browsers.
required attribute
Now, we don’t need to use JavaScript to handle client-side validations such as empty text boxes that can never be submitted, because HTML5 introduces a new attribute called required Attributes can be used as follows, which will ensure that the input box has a value:
This attribute is only supported by the latest versions of Mozilla, Safari and Chrome browsers.