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]