input标签的属性归纳html/html5

<input>在 HTML 中适用的属性和值
属性描述
acceptaudio/*video/*image/*MIME_type规定通过文件上传来提交的文件的类型。 (只针对type="file")
alignleft、right、top、middle、bottomHTML5已废弃,不赞成使用。规定图像输入的对齐方式。 (只针对type="image")
alttext定义图像输入的替代文本。 (只针对type="image")
checkedcheckedchecked 属性规定在页面加载时应该被预先选定的 <input> 元素。 (只针对 type="checkbox" 或者 type="radio")
disableddisableddisabled 属性规定应该禁用的 <input> 元素。
maxlengthnumber属性规定 <input> 元素中允许的最大字符数。
nametextname 属性规定 <input> 元素的名称。
readonlyreadonlyreadonly 属性规定输入字段是只读的。
sizenumbersize 属性规定以字符数计的 <input> 元素的可见宽度。
srcURLsrc 属性规定显示为提交按钮的图像的 URL。 (只针对 type="image")
valuetext指定 <input> 元素 value 的值。
typebuttoncheckboxcolor datedatetime
datetime-localemailfilehiddenimage
monthnumberpasswordradiorangereset
searchsubmitteltexttimeurlweek
type 属性规定要显示的 <input> 元素的类型。



<input>在 HTML5 中新增的属性和值
属性描述
autocompleteonoff autocomplete 属性规定 <input> 元素输入字段是否应该启用自动完成功能。
autofocusautofocus属性规定当页面加载时 <input> 元素应该自动获得焦点。
formform_idform 属性规定 <input> 元素所属的一个或多个表单。
formactionURL属性规定当表单提交时处理输入控件的文件的 URL。(只针对 type="submit" 和 type="image")
formenctypeapplication/x-www-form-urlencodedmultipart/form-datatext/plain属性规定当表单数据提交到服务器时如何编码(只适合 type="submit" 和 type="image")。
formmethodgetpost定义发送表单数据到 action URL 的 HTTP 方法。 (只适合 type="submit" 和 type="image")
formnovalidateformnovalidateformnovalidate 属性覆盖 <form> 元素的 novalidate 属性。
formtarget_blank_self_parent_top framename规定表示提交表单后在哪里显示接收到响应的名称或关键词。(只适合 type="submit" 和 type="image")
heightpixels规定 <input>元素的高度。(只针对type="image")
listdatalist_id属性引用 <datalist> 元素,其中包含 <input> 元素的预定义选项。
maxnumberdate属性规定 <input> 元素的最大值。
minnumberdate属性规定 <input> 元素的最小值。
multiplemultiple属性规定允许用户输入到 <input> 元素的多个值。
patternregexppattern 属性规定用于验证 <input> 元素的值的正则表达式。
placeholdertextplaceholder 属性规定可描述输入 <input> 字段预期值的简短的提示信息 。
requiredrequired属性规定必需在提交表单之前填写输入字段。
stepnumberstep 属性规定 <input> 元素的合法数字间隔。
widthpixelswidth 属性规定 <input> 元素的宽度。 (只针对type="image")


常用input类型[type]

注意:

  1. 区分[type=“button”]和[type=“submit”]:button默认时,不会提交数据或者任何数据,就一个存粹的按钮。submit则会提交整个表单的数据到后台。
  2. 语义化:<form> 里用的文本标签是<label> ,而不是<p>/<a>。
    👉传送门:input type=“submit” 和"button"有什么区别
  3. CSS渲染input元素,用属性选择器标签[属性=值],因为input没有class,id有些可以不设,所以属性选择器就方便许多。可以为:
    input[type=text](选取属性类型为text的input标签);
    input[id=name](选取属性id为text的input标签);
    input[value=1](选取属性value为1的input标签);
  4. <label for=id><input id="">配合工作。
    👉传送门:浅谈与合作的两种方式
  5. 区分id属性和name属性:①表单数据以name提交,而css渲染、js获取对象则是id;②id要符合标识的要求,比如大小写敏感,最好不要包含下划线(因为不兼容CSS)。而name基本上没有什么要求,甚至可以用数字。
    👉传送门:input中name和id的区别
ps:
①当然,如果有id,也可以id选择器: #id
②属性选择器内的值,可以加单/双引号,如: input[type="text"]
③虽然 <button></button><input type="button">是同一种功能,但:
a、 <button></button>有结束标签, <input type="button">是空标签;
b、 <input type="button">里面想要添加文本内容只能在value设置,而 <button></button>,因为有起始和结束标签,所以能插入其它元素。
怎么用看场景和个人喜欢了。

在这里插入图片描述

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<!--
<link rel="stylesheet" href="css/reset.css" />
<link rel="stylesheet" href="css/common.css" />
<link rel="stylesheet" href="css/index.css" />
-->
<style type="text/css">
/*reset.css*/
body, h1, h2, h3, h4, h5, h6, dl, dt, dd, ol, ul, li, p, a, input, form, textarea {
	padding: 0;
	margin: 0;
	font-family: 'Microsoft YaHei';
}

ol, ul, li {
	list-style: none;
}

img {
	display: block;
	border: none;
}

a {
	display: block;
	text-decoration: none;
}

.clearfix {
	zoom: 1;
}

.clearfix:after {
	display: block;
	content: '';
	clear: both;
	visibility: hidden;
	height: 0;
}

/*common.css*/
.bg {
	min-width: 100%;
	min-height: 100%;
	background: #fcc;
	position: absolute;
}

.container {
	width: 1070px;
	margin: 0 auto;
}

/*index.css*/
.header {
	height: 200px;
}

.main {
	background: rgba(255, 255, 255, 0.4);
}

.footer {
	height: 100px;
}

#user-name {			/* id 选择器;id要符合标识的要求,比如大小写敏感,最好不要包含下划线*/
	background: rgba( 0, 0, 0, 0.2);
}

input[id=user-password] {		/*属性选择器;id要符合标识的要求,比如大小写敏感,最好不要包含下划线*/
	background: rgba( 0, 0, 155, 0.2);
}

input[name=btn] {			/*属性选择器*/
	width: 100px;
	height: 30px;
	font-size: 20px;
	border-radius: 25px;
}

input[value=提交] {			/*属性选择器,当value为中文符号时,建议选其他属性,而不是带有中文符号的属性*/
	padding: 0 20px 2px;
	font-size: 15px;
	color: #fff;
	background: rgba(155, 0, 200, 0.2);
}

input[type=reset] {			/*属性选择器*/
	width: 80px;
	height: 30px;
	font-size: 18px;
	line-height: 18px;
	color: #fff;
	background: rgba(0, 0, 0, 1);
}

textarea[name=comments] {		/*属性选择器*/
	width: 200px;
	height: 50px;
	font-size: 20px;
	color: #fff;
	padding: 5px;
  	border: 2px solid #ccc;
  	background-color: rgba(0, 0, 0, 0.2);
}
</style>
</head>

<body>
	<div class="bg">
		<div class="header container"></div>
		<div class="main container">
			<div class="wrap">
				<form>
					<label for="user-name">【type="text"】姓名:</label>
					<input type="text" id="user-name" name="user_name" /><!--注意id和name-->
					<br />
					<label for="user-password">【type="password"】密码:</label>
					<input type="password" id="user-password" name="user_password" /><!--注意id和name-->
					<br />
					<label for="btn">【type="button"】点击按钮:</label>
					<input type="button" id="btn" name="btn" value="按钮"  />
					<br />
					<label for="sbt">【type="submit"】提交按钮:</label>
					<input type="submit" id="sbt" name="sbt" value="提交" />
					<br />
					<label for="rst">【type="reset"】重置按钮:</label>
					<input type="reset" id="rst" name="rst" value="重置" />
					<br />
					<label for="gender">【type="radio"】性别:</label>
					<input type="radio" id="gender" name="gender" value="female" /><input type="radio" id="gender" name="gender" value="male" /><br />
					<label for="hobby">【type="checkbox"】爱好:</label>
					<input type="checkbox" name="hobby[]" value="A" />A
					<input type="checkbox" name="hobby[]" value="B" />B
					<input type="checkbox" name="hobby[]" value="C" />C
					<br />
					<label for="up-img">【type="file"】上传文件:</label>
					<input type="file" id="up-img" name="up-img">
					<br />
					<label for="week">【select+option】星期</label>
					<select id="week" name="week">
						<option value="1"></option>
						<option value="2"></option>
						<option value="3"></option>
						<option value="4"></option>
						<option value="5"></option>
						<option value="6"></option>
						<option value="7"></option>
					</select>
					<br />
					<label for="text-area">文本域:</label>
					<textarea id="text-area" name="text-area" cols="20" rows="4">请输入内容...</textarea>
					<br />
					<label for="comments">评论:</label>
					<textarea id="comments" name="comments">请输入内容...</textarea>
				</form>
			</div>
		</div>
		<div class="footer container"></div>
	</div>
</body>
</html>

题外话:同代码,IE浏览器与非IE浏览器比,IE出来的渲染效果太不美观了

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值