HTML 5新的 Input 类型

开发 前端
HTML5 拥有多个新的表单输入类型。这些新特性提供了更好的输入控制和验证。本文将介绍HTML5 新的 Input 类型。

HTML5 拥有多个新的表单输入类型。这些新特性提供了更好的输入控制和验证。

介绍这些新的输入类型:

  • email
  • url
  • number
  • range
  • Date pickers (date, month, week, time, datetime, datetime-local)
  • search
  • color
  • telephone
  • color

EMAIL

  1. <input type="email" /> 

在提交表单时会自动验证email的格式

效果:

HTML

URL

  1. <input type="url" /> 

在提交表单时会自动验证url的格式

效果:

HTML

NUMBER

  1. <input type="number" max="9" min="0" step="2"/> 

可以限制输入的数字,step为上一个数字与下一个数字的间隔

效果:

HTML

RANGE

  1. <input type="range"  min="1" max="10" /> 

滑动条,能过选择性的对限制范围内的数值进行设置

效果:

HTML

Date Pickers(数据检出器)

HTML5 拥有多个可供选取日期和时间的新输入类型:

  • date - 选取日、月、年
  • month - 选取月、年
  • week - 选取周和年
  • time - 选取时间(小时和分钟)
  • datetime - 选取时间、日、月、年(UTC 时间)
  • datetime-local - 选取时间、日、月、年(本地时间)

This is how Opera renders <input type="date">:

HTML 5 

If you need a time to go with that date, Opera also supports <input type="datetime">:

HTML 5 

If you only need a month + year (perhaps a credit card expiration date), Opera can render a <input type="month">:

 HTML 

Less common, but also available, is the ability to pick a specific week of a year with <input type="week">:

 

Last but not least, you can pick a time with <input type="time">:

HTML 5

地址:http://diveintohtml5.org/forms.html

以上都是从关于时间的都是网上找到,自己做的是这样的

HTML 5

其中图片中显示的UTC为世界统一时间

SEARCH

  1. <input id="search" type="url" list="searchlist" required /> 
  2. <datalist id="searchlist"> 
  3.                 <option value="http://www.google.com" label="Google" /> 
  4.                 <option value="http://www.yahoo.com" label="Yahoo" /> 
  5.                 <option value="http://www.bing.com" label="Bing" /> 
  6. </datalist> 

这里的datalist相当于下拉列表,可以进行选择

效果:

HTML 5

TELEPHONE

  1. <input type="telephone" /> 

可输入一个电话号码

效果:

HTML 5

COLOR

  1. <input type="color"/> 

可以获取颜色

效果:

HTML 5

以上个人图片效果显示均来自opera浏览器

下面图片时各主流浏览器对input的支持情况:

HTML 5

input标签表单类型的显示情况:
 

HTML 5 

【编辑推荐】

  1. 12个精妙有趣的HTML 5应用
  2. 20个HTML 5和CSS3的免费网站模板与教程
  3. 10个国外开发的HTML 5精彩应用
  4. 初学者必知的HTML 5入门级技巧
责任编辑:陈贻新 来源: 神舟龙的博客
相关推荐

2011-07-12 13:21:34

2011-08-30 09:07:30

HTML 5

2011-11-09 10:05:26

HTML 5

2010-08-25 11:32:34

2011-01-25 08:55:39

HTML 5webW3C

2009-09-25 10:23:51

HTML 5新特性

2011-04-25 14:20:49

DojoHTML 5

2011-07-14 09:16:10

HTML 5

2011-07-19 13:39:20

iOS HTML5

2011-04-22 15:02:19

HTML5Dojo

2011-11-18 13:25:48

HTML 5

2012-05-28 15:31:57

App-UI

2015-08-28 10:47:48

Windows 10EdgeHTML

2021-12-13 22:52:37

iphone iOSHTML

2013-01-24 10:26:04

HTML5HTML 5HTML5的未来

2016-12-14 13:41:49

HTML 5浏览器VDI

2011-09-14 14:25:00

HTML 5

2011-05-13 17:36:05

HTML

2022-04-22 15:53:12

5G4G运营商

2014-11-10 11:02:21

点赞
收藏

51CTO技术栈公众号