input禁止输入的方法

1: readonly规定输入字段为只读可复制,但是,用户可以使用Tab键切换到该字段,可选择,可以接收焦点,还可以选中或拷贝其文本。

<input type="text" value="哈哈哈" readonly="readonly">

2:disabled   被禁用的 input 元素可复制,不能接收焦点,设置后文字的颜色会变成灰色。无法与 <input type="hidden"> 一起使用。

<input type="text" value="哈哈哈" disabled="disabled">

3:通过控制input的max length为0实现

<input type="text"  maxlength="0">

4:onfocus="this.blur();"onfocuse是聚焦的意思,当你把光标放在文本框上输入的时候,就是聚焦,但这里添加了"this.blur()",blur的作用就是去除聚焦,也就是你不能把光标放在这个文本框上,换句话说就是你不能输入文本了 

<input type="text" value="哈哈哈" onfocus="this.blur();">

猜你喜欢

转载自www.cnblogs.com/handsome-boy/p/9209827.html