Home >Web Front-end >H5 Tutorial >Detailed introduction and example code of HTML5 Input type
HTML5 has several new form input types. These new features provide better input control and validation.
This chapter provides a comprehensive introduction to these new input types:
1.color
2.date
3.datetime
4.datetime-local
5.email
6.month
7.number
8.range
9.search
10.tel
11.time
12.url
13.week
Note: Not all major browsers support the new input types, but you can already use them in all major browsers. Even if it is not supported, it can still be displayed as a regular text field.
Input type: color
The color type is used in the input field and is mainly used to select colors, as shown below:
Example
From the color picker Select a color:
Choose a color you like:
<input type="color" name="favcolor">
Input type: date
date type allows you to select a date picker date.
Example
Define a timeController:
生日: <input type="date" name="bday">
Input type: datetime
The datetime type allows you to select a date ( UTC time).
Example
Define a date and time controller (local time):
生日 (日期和时间): <input type="datetime" name="bdaytime">
Input type: datetime-local
datetime-local type allows you Select a date and time (without time zone).
Example
Define a date and time (without time zone):
生日 (日期和时间): <input type="datetime-local" name="bdaytime">
Input Type: email
The email type is used for input fields that should contain e-mail addresses.
Example
When submitting the form, it will automatically verify whether the value of the email field is legal and valid:
E-mail: <input type="email" name="email">
Tips: Safari browser on iPhone Supports the email input type and changes the touch screen keyboard to suit it (added @ and .com options).
Input Type: month
The month type allows you to select a month.
Example
Definition of month and year (no time zone):
生日 (月和年): <input type="month" name="bdaymonth">
Input type: number
number type is used for input fields that should contain numerical values.
You can also set limits on the numbers accepted:
Example
Define a numeric input field (limitation):
Quantity (1 to 5):
<input type="number" name="quantity" min="1" max="5">
Use the following attributes to specify limits on numeric types:
max- Specifies the maximum allowed value
min - specifies the minimum allowed value
step - specifies the legal number interval (if step="3", the legal number is -3,0,3,6, etc.)
value - Specify default values
Try the example with all qualified attributesTry it
Input type: range
range type is used for inputs that should contain numeric values within a certain range area.
Range types are displayed as sliders.
Example
定义一个不需要非常精确的数值(类似于滑块控制):
<input type="range" name="points" min="1" max="10">
请使用下面的属性来规定对数字类型的限定:
max - 规定允许的最大值
min - 规定允许的最小值
step - 规定合法的数字间隔
value - 规定默认值
Input 类型: search
search 类型用于搜索域,比如站点搜索或 Google 搜索。
实例
定义一个搜索字段 (类似站点搜索或者Google搜索):
Search Google: <input type="search" name="googlesearch">
Input 类型: tel
实例
定义输入电话号码字段:
电话号码: <input type="tel" name="usrtel">
Input 类型: time
time 类型允许你选择一个时间。
实例
定义可输入时间控制器(无时区):
选择时间: <input type="time" name="usr_time">
Input 类型: url
url 类型用于应该包含 URL 地址的输入域。
在提交表单时,会自动验证 url 域的值。
实例
定义输入URL字段:
添加您的主页: <input type="url" name="homepage">
提示: iPhone 中的 Safari 浏览器支持 url 输入类型,并通过改变触摸屏键盘来配合它(添加 .com 选项)。
Input 类型: week
week 类型允许你选择周和年。
实例
定义周和年 (无时区):
选择周: <input type="week" name="week_year">
【相关推荐】
1. 特别推荐:“php程序员工具箱”V0.1版本下载
2. 免费h5在线视频教程
The above is the detailed content of Detailed introduction and example code of HTML5 Input type. For more information, please follow other related articles on the PHP Chinese website!