HTML input type 输入类型
来源:互联网 发布:热门小说大全软件 编辑:程序博客网 时间:2024/06/05 19:12
本章描述 <input> 元素的输入类型。
输入类型:text
<input type="text"> 定义供文本输入的单行输入字段:
实例
<form> First name:<br><input type="text" name="firstname"><br> Last name:<br><input type="text" name="lastname"></form>
以上 HTML 代码在浏览器中看上去是这样的:
输入类型:password
<input type="password"> 定义密码字段:
实例
<form> User name:<br><input type="text" name="username"><br> User password:<br><input type="password" name="psw"></form>
以上 HTML 代码在浏览器中看上去是这样的:
注释:password 字段中的字符会被做掩码处理(显示为星号或实心圆)。
输入类型:submit
<input type="submit"> 定义提交表单数据至表单处理程序的按钮。
表单处理程序(form-handler)通常是包含处理输入数据的脚本的服务器页面。
在表单的 action 属性中规定表单处理程序(form-handler):
实例
<form action="action_page.php">First name:<br><input type="text" name="firstname" value="Mickey"><br>Last name:<br><input type="text" name="lastname" value="Mouse"><br><br><input type="submit" value="Submit"></form>
以上 HTML 代码在浏览器中看上去是这样的:
如果您省略了提交按钮的 value 属性,那么该按钮将获得默认文本:
实例
<form action="action_page.php">First name:<br><input type="text" name="firstname" value="Mickey"><br>Last name:<br><input type="text" name="lastname" value="Mouse"><br><br><input type="submit"></form>
Input Type: radio
<input type="radio"> 定义单选按钮。
Radio buttons let a user select ONLY ONE of a limited number of choices:
实例
<form><input type="radio" name="sex" value="male" checked>Male<br><input type="radio" name="sex" value="female">Female</form>
以上 HTML 代码在浏览器中看上去是这样的:
Input Type: checkbox
<input type="checkbox"> 定义复选框。
复选框允许用户在有限数量的选项中选择零个或多个选项。
实例
<form><input type="checkbox" name="vehicle" value="Bike">I have a bike<br><input type="checkbox" name="vehicle" value="Car">I have a car </form>
以上 HTML 代码在浏览器中看上去是这样的:
Input Type: button
<input type="button> 定义按钮。
实例
<input type="button" onclick="alert('Hello World!')" value="Click Me!">
以上 HTML 代码在浏览器中看上去是这样的:
HTML5 输入类型
HTML5 增加了多个新的输入类型:
- color
- date
- datetime
- datetime-local
- month
- number
- range
- search
- tel
- time
- url
- week
注释:老式 web 浏览器不支持的输入类型,会被视为输入类型 text。
输入类型:number
<input type="number"> 用于应该包含数字值的输入字段。
您能够对数字做出限制。
根据浏览器支持,限制可应用到输入字段。
实例
<form> Quantity (between 1 and 5): <input type="number" name="quantity" min="1" max="5"></form>
输入限制
这里列出了一些常用的输入限制(其中一些是 HTML5 中新增的):
您将在下一章学到更多有关输入限制的知识。
实例
<form> Quantity: <input type="number" name="points" min="0" max="100" step="10" value="30"></form>
输入类型:date
<input type="date"> 用于应该包含日期的输入字段。
根据浏览器支持,日期选择器会出现输入字段中。
实例
<form> Birthday: <input type="date" name="bday"></form>
您可以向输入添加限制:
实例
<form> Enter a date before 1980-01-01: <input type="date" name="bday" max="1979-12-31"><br> Enter a date after 2000-01-01: <input type="date" name="bday" min="2000-01-02"><br></form>
输入类型:color
<input type="color"> 用于应该包含颜色的输入字段。
根据浏览器支持,颜色选择器会出现输入字段中。
实例
<form> Select your favorite color: <input type="color" name="favcolor"></form>
输入类型:range
<input type="range"> 用于应该包含一定范围内的值的输入字段。
根据浏览器支持,输入字段能够显示为滑块控件。
实例
<form> <input type="range" name="points" min="0" max="10"></form>
您能够使用如下属性来规定限制:min、max、step、value。
输入类型:month
<input type="month"> 允许用户选择月份和年份。
根据浏览器支持,日期选择器会出现输入字段中。
实例
<form> Birthday (month and year): <input type="month" name="bdaymonth"></form>
输入类型:week
<input type="week"> 允许用户选择周和年。
根据浏览器支持,日期选择器会出现输入字段中。
实例
<form> Select a week: <input type="week" name="week_year"></form>
输入类型:time
<input type="time"> 允许用户选择时间(无时区)。
根据浏览器支持,时间选择器会出现输入字段中。
实例
<form> Select a time: <input type="time" name="usr_time"></form>
输入类型:datetime
<input type="datetime"> 允许用户选择日期和时间(有时区)。
根据浏览器支持,日期选择器会出现输入字段中。
实例
<form> Birthday (date and time): <input type="datetime" name="bdaytime"></form>
输入类型:datetime-local
<input type="datetime-local"> 允许用户选择日期和时间(无时区)。
根据浏览器支持,日期选择器会出现输入字段中。
实例
<form> Birthday (date and time): <input type="datetime-local" name="bdaytime"></form>
输入类型:email
<input type="email"> 用于应该包含电子邮件地址的输入字段。
根据浏览器支持,能够在被提交时自动对电子邮件地址进行验证。
某些智能手机会识别 email 类型,并在键盘增加 ".com" 以匹配电子邮件输入。
实例
<form> E-mail: <input type="email" name="email"></form>
输入类型:search
<input type="search"> 用于搜索字段(搜索字段的表现类似常规文本字段)。
实例
<form> Search Google: <input type="search" name="googlesearch"></form>
输入类型:tel
<input type="tel"> 用于应该包含电话号码的输入字段。
目前只有 Safari 8 支持 tel 类型。
实例
<form> Telephone: <input type="tel" name="usrtel"></form>
输入类型:url
<input type="url"> 用于应该包含 URL 地址的输入字段。
根据浏览器支持,在提交时能够自动验证 url 字段。
某些智能手机识别 url 类型,并向键盘添加 ".com" 以匹配 url 输入。
实例
<form> Add your homepage: <input type="url" name="homepage"></form>
- HTML input type 输入类型
- html input type的各种类型
- HTML正则表达式:限制Input输入类型
- HTML Input 标签限制输入类型
- HTML输入类型(input元素)
- HTML 18.3 表单元素input的输入属性type
- html的input几种type类型的内容。
- html中的input type="file"类型内容清空
- HTML <input> type 属性
- 关于HTML中input标签的新输入类型
- html input输入限制
- 限制input输入类型
- 限制input输入类型
- 限制input输入类型
- HTML 5 <input> type 属性
- HTML 5 <input> type 属性
- input元素属性type类型
- Input对象的type类型
- Android Studio曲折更新之路
- 常用排序算法总结
- 图论学习之二分图(一)二分图的概念及基本算法
- C++primer[习题][第三章][21-30]
- HDOJ1012 u Calculate e
- HTML input type 输入类型
- hiho 1643最少换乘 O(n)复杂度
- HDOJ 2136 Largest prime factor
- android 运用tensorflow以及遇到的问题
- KaFka单机安装
- Eureka、Ribbon和Feign
- Hash长度扩展攻击--MD5
- BDTC 2017丨大数据在金融、交通、医疗、工业领域落地实践与应用
- javascript中的原型与继承1--原型链Prototype Chaining