readonly和disabled

readonly和disabled的异同点

1、readonly属性规定输入字段是只读的;disabled属性规定应该禁用的<input>元素。
2、但是readonly可以提交给服务器,disabled数据不会提交(即使有name属性也不会提交)。
3、都是只读不能修改。

代码示例
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>readonly和disabled</title>
	</head>
	<body>
		<form action="http://localhost:8080/html/test">
			用户代码:<input type="text" 
						name="usercode" value="111" 
						readonly /><br>
			用户姓名:<input type="text" 
						name="username" value="zhangsan" 
						disabled /><br>
			<input type="submit" value="提交数据" />
		</form>
	</body>
</html>

在这里插入图片描述
点击提交数据之后:
在这里插入图片描述
可以看出:
readonly可以提交给服务器,disabled数据不会提交。

maxlength

设置文本框中可输入的最大字符数量。

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>maxlength属性</title>
	</head>
	<body>
		<input type="text" maxlength="5" />
	</body>
</html>

在这里插入图片描述

原文地址:https://www.cnblogs.com/yu011/p/13503357.html