This article mainly introduces the new Input type of HTML5, which has certain reference value. Now I share it with you. Friends in need can refer to it
Inpute type: color
The color type is used in the input field and is mainly used to select colors, as shown below:
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8" /> <title>自选教程(如约智惠.com)</title> </head> <body > <form action="demo-form.php"> 选择你喜欢的颜色: <input type="color" name="favcolor"><br /> <input type="submit"> </form> </body> </html>
Input type: date
# The date type allows you to select a date from a date picker.
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8" /> <title>自选教程(如约智惠.com)</title> </head> <body > <form action="demo-form.php"> 生日: <input type="date" name="bday"><br /> <input type="submit"> </form> </body> </html>
Input type: datetime
The datetime type allows you to select a date (UTC time)
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8" /> <title>自选教程(如约智惠.com)</title> </head> <body > <form action="demo-form.php"> 生日(日期和时间): <input type="datetime" name="bdaytime"><br /> <input type="submit"> </form> </body> </html>
Input type: datetime-local
datetime- The local type allows you to select a date and time (no time zone)
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8" /> <title>自选教程(如约智惠.com)</title> </head> <body > <form action="demo-form.php"> 生日(日期和时间): <input type="datetime-local" name="bdaytime"><br /> <input type="submit"> </form> </body> </html>
Input type: email
email type For input fields that should contain e-mail addresses
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8" /> <title>自选教程(如约智惠.com)</title> </head> <body > <form action="demo-form.php"> E-mail: <input type="email" name="usremail"><br /> <input type="submit"> </form> </body> </html>
Input type:month
## The month type allows you Select a month
生日 (月和年): <input type="month" name="bdaymonth">
The number type is used to contain Input field for numeric values.
You can also set limits on the numbers accepted:
Define a numeric input field (limitation):数量 ( 1 到 5 之间 ): <input type="number" name="quantity" min="1" max="5">
Use the following attributes to specify restrictions on numeric types:
Attribute | Description |
---|---|
disabled | Specifies that the input field is disabled |
max | Specifies the maximum allowed value |
maxlength | Specifies the maximum character length of the input field |
min | Specifies the minimum value allowed |
pattern | Specifies the pattern used to validate the input field |
readonly | Specifies that the value of the input field cannot be modified |
required | Specifies that the value of the input field is required |
size | Specifies the number of visible characters in the input field |
step | Specify the legal number interval of the input field |
value | Specify the default value of the input field |
range 类型用于应该包含一定范围内数字值的输入域。
range 类型显示为滑动条。
定义一个不需要非常精确的数值(类似于滑块控制):
<input type="range" name="points" min="1" max="10">
请使用下面的属性来规定对数字类型的限定:
max - 规定允许的最大值
min - 规定允许的最小值
step - 规定合法的数字间隔
value - 规定默认值
search 类型用于搜索域,比如站点搜索或 Google 搜索。
定义一个搜索字段 (类似站点搜索或者Google搜索):
Search Google: <input type="search" name="googlesearch">
定义输入电话号码字段:
电话号码: <input type="tel" name="usrtel">
time 类型允许你选择一个时间。
定义可输入时间控制器(无时区):
选择时间: <input type="time" name="usr_time">
url 类型用于应该包含 URL 地址的输入域。
在提交表单时,会自动验证 url 域的值。
定义输入URL字段:
添加您的主页: <input type="url" name="homepage">
提示: iPhone 中的 Safari 浏览器支持 url 输入类型,并通过改变触摸屏键盘来配合它(添加 .com 选项)。
week 类型允许你选择周和年。
定义周和年 (无时区):
选择周: <input type="week" name="week_year">
注意:并不是所有的主流浏览器都支持新的input类型,不过您已经可以在所有主流的浏览器中使用它们了。即使不被支持,仍然可以显示为常规的文本域。
相关推荐:
The implementation of HTML5 offline application and client storage
The above is the detailed content of HTML5 new Input type. For more information, please follow other related articles on the PHP Chinese website!