input标签里面type常用属性(注册登录表单常用元素)

之前写一些小项目的时候,在表单这一块因为知道的type属性就text、password、button、submit等一些值,而且form表单也应用的不是很灵活,所以通过简单的学习,认识到以前写的form表单有多搞笑(连type=data都不知道)。

现在,就对form表单里常用的元素进行整理。

type值代表的含义
text文本
password密码
button按钮
file文件
checkbox复选框
hidden定义隐藏的输入字段
image定义图像形式的提交按钮
radio单选框
reset重置
tel手机号码
email邮箱地址
number数字
date日期

上述表单就是一些常用的表单元素,如有不足,欢迎雅正!

再更新一些:

新增的input type属性值:

类型使用示例含义
email<input type="email>输入邮箱格式
tel<input type=“tel”>输入手机号码格式
url<input type=“url”>输入url格式
number<input type=“number”>输入数字格式
search<input type=“search”>搜索框(体现语义化)
range<input type=“range”>自由拖动滑块
time<input type=“time”>小时分钟
date<input type=“date”>年月日
datetime<input type=“datetime”>时间
month<input type=“month”>月年
week<input type=“week”>星期 年

常用新属性

属性用法含义
placeholder<input type=“text” placeholder=“请输入用户名”>占位符 当用户输入的时候 里面的文字消失 删除所有文字,自动返回
autofocus<input type=“text” autofocus>规定当页面加载时 input 元素应该自动获得焦点
multiple<input type=“file” multiple>多文件上传
autocomplete<input type=“text” autocomplete=“off”>规定表单是否应该启用自动完成功能 有2个值,一个是on 一个是off on 代表记录已经输入的值 1.autocomplete 首先需要提交按钮
2.这个表单您必须给他名字
required<input type=“text” required>必填项 内容不能为空
accesskey<input type=“text” accesskey=“s”>规定激活(使元素获得焦点)元素的快捷键 采用 alt + s的形式

下面在给出一个简单的html例子作为参考

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<body>
		<!--<table width="600" border="1px" cellpadding="0" cellspacing="0">
			<caption><h4>青春不常在,抓紧谈恋爱</h4></caption>
		</table>-->
		<form action="">
			<!--当一组表单元素放到fieldset标签内时,浏览器会以特殊的方式来显示它们,它们可能有特殊的
				边界、3D效果,或者甚至可创建一个子表单来处理这些元素
			-->
		  <fieldset>
		  	<!--legend元素为fieldset元素定义的标题-->
		    <legend>学生档案</legend>
		    <label for="userName">姓名:</label>
		    <input type="text" name="userName" id="userName" placeholder="请输入用户名"> <br>
		    <label for="userPhone">手机号码:</label>
		    <input type="tel" name="userPhone" id="userPhone" pattern="^1\d{10}$"><br>
		    <label for="email">邮箱地址:</label>
		    <input type="email" required name="email" id="email"><br>
		    <label for="collage">所属学院:</label>
		    <input type="text" name="collage" id="collage" list="cList" placeholder="请选择"><br>
		    <datalist id="cList">
		      <option value="前端与移动开发学院"></option>
		      <option value="java学院"></option>
		      <option value="c++学院"></option>
		    </datalist><br>
		    <label for="score">入学成绩:</label>
		    <input type="number" max="100" min="0" value="0" id="score"><br>
		   	<form action="">
			    <fieldset>
			    	<legend>学生档案思密达</legend>
			    	<label>姓名: <input type="text" placeholder="请输入学生名字"/></label> <br /><br />
			    	<label>手机号: <input type="tel" /></label> <br /><br />
			    	<label>邮箱: <input type="email" /></label> <br /><br />
			    	<label>所属学院:  <input type="text" placeholder="请选择学院" list="xueyuan"/>
			    	<datalist id="xueyuan">
			    		<option>java学院</option>
			    		<option>前端学院</option>
			    		<option>php学院</option>
			    		<option>设计学院</option>
			    	</datalist>
			
			    	<br /><br />
			
			    	<label>出生日期:   <input type="date" /></label> <br /><br />
			    	<label>成绩:  <input type="number" /></label> <br /><br />
			    	<label>毕业时间:  <input type="date" /></label> <br /><br />
			    	<input type="submit" />  <input type="reset" />
			    </fieldset>
		    </form>
		    <label for="inTime">入学日期:</label>
		    <input type="date" id="inTime" name="inTime"><br>
		    <label for="leaveTime">毕业日期:</label>
		    <input type="date" id="leaveTime" name="leaveTime"><br>
		    <input type="submit">
		  </fieldset>
		</form>
	</body>
</html>

展示界面
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值