HTML5 new Input type

Input type: color

    The color type is mainly used in the input field to select the color, as shown below:

<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8" />
		<title>Self-selected course (such as about Zhihui.com)</title>
		
	</head>
	<body >
		<form action="demo-form.php">
			Choose your favorite color:
			<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>Self-selected course (such as about Zhihui.com)</title>
		
	</head>
	<body >
		<form action="demo-form.php">
			Birthday:
			<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>Self-selected course (such as about Zhihui.com)</title>
		
	</head>
	<body >
		<form action="demo-form.php">
			Birthday (date and time):
			<input type="datetime" name="bdaytime"><br />
			<input type="submit">
		</form>
		
	</body>
</html>

Input type: datetime-local

    The datetime-local type allows you to select a date and time (no time zone)

<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8" />
		<title>Self-selected course (such as about Zhihui.com)</title>
		
	</head>
	<body >
		<form action="demo-form.php">
			Birthday (date and time):
			<input type="datetime-local" name="bdaytime"><br />
			<input type="submit">
		</form>
		
	</body>
</html>

Input type: email

    The email type is used for input fields that should contain the e-mail address

<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8" />
		<title>Self-selected course (such as about Zhihui.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 to select a month

生日 (月和年): <input type="month" name="bdaymonth">

Input Type: number

   The number type is used for input fields that should contain numeric values.

   You can also set limits on accepted numbers:


Define a numeric input field (qualified):

数量 ( 1 到 5 之间 ): <input type="number" name="quantity" min="1" max="5">


   Use the following attributes to specify constraints on numeric types:

Attributes describe
disabled Specifies that the input field is disabled
max Specifies the maximum value allowed
maxlength Specifies the maximum character length of the input field
min Specifies the minimum allowable value
pattern Specifies the schema used to validate input fields
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 Specifies the legal number interval for input fields
value Specifies default values ​​for input fields

Input Type: range

   The range type is used for input fields that should contain a range of numeric values.

   The range type is displayed as a slider.

Define a value that doesn't need to be very precise (similar to a slider control):

<input type="range" name="points" min="1" max="10">


Please use the following attributes to specify restrictions on numeric types:

  • max - specifies the maximum value allowed
  • 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">


注意:并不是所有的主流浏览器都支持新的input类型,不过您已经可以在所有主流的浏览器中使用它们了。即使不被支持,仍然可以显示为常规的文本域。


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325642635&siteId=291194637