1、CSS去掉谷歌浏览器的黄色背景
input:-webkit-autofill {
-webkit-box-shadow: 0 0 0px 1000px white inset;
}
2、限制input框输入的字符长度 maxlength 属性
例:<input type="text" maxlength="10">;(input框只能输入10个字符)。
3、 input禁止输入 readonly 属性 只读:
例:<input type="text" readonly="readonly" placeholder="禁止输入文字" >
4、input 禁止浏览器自动记录输入的值 autocomplete 属性
例:<input type="text" autocomplete="new-password" placeholder="禁止记录输入文字" >
5、input禁止输入空格(禁止使用空格键)
<input type="password" onKeypress="javascript:if(event.keyCode == 32)event.returnValue = false;" placeholder="请确认您的密码"/>
6、input禁止粘贴 onpaste="return false;"
例:
<input type="password" onpaste="return false;" placeholder="请输入您的密码">
7、只能包含三个字母的文本字段(数字或特殊字符) pattern属性:
例:
<input type="text" name="country_code" pattern="[A-z]{3}" title="Three letter country code" />