input禁止输入的4种方法
1
|
<input type=
"text"
value=
"哈哈哈"
readonly
=
"readonly"
>
//使用readonly,字段为只读可复制
|
方法2、 disabled
1
|
<input type=
"text"
value=
"哈哈哈"
disabled=
"disabled"
>
//只读不可复制,无法选择, 文字会变成灰色
|
方法3、max length = “0”
1
|
<input type=
"text"
maxlength=
"0"
>
|
方法4:this.blur()
1
|
<input type=
"text"
value=
"哈哈哈"
onfocus=
"this.blur();"
>
|
<input name="result" id="result" type="text" onFocus="this.blur();" size="20" value="">
是一个输入框,用户输入文本的框就是类似于百度的搜索框,大小是20,value=""说明初始为空
onfocuse="this.blur()"
onfocuse是聚焦的意思,当你把光标放在文本框上输入的时候,就是聚焦,但这里添加了"this.blur()",blur的作用就是去除聚焦,也就是你不能把光标放在这个文本框上,换句话说就是你不能输入文本了
----------
[color=red]整个代码构成了"不能输入任何文本的文本框"[/color]