如使<input type = "text" name = "country" id = "country" value = "中国">的内容,“中国“两个字不可修改,实现的方法总解如下:
(1)onfocuse = this.blur()
代码复制如下:
<input type = "text" name = "country" id = "country" value = "中国" onfocus = this.blur()>
分析:onfocuse = this.blur()
onfocuse 是聚焦的意思,当你把光标放在文本框上输入的时候,就是聚焦,但是添加了"this.blur()",blur的作用是去除聚焦,也就是你不能把光标放在文本框上,换句话说你不能输入文本框了。
整个代码就构成了不能输入任何文本的文本框。
适用范围:input单文本/多文本
(2)添加readonly的属性
代码复制如下:
<input type = "text" name = "country" id = "country" value ="中国" readonly>
或者:<input type = "text" name = "country" id = "country" value ="中国" readonly = “true”>
或者:<input type = "text" name = "country" id = "country" value ="中国" readonly = "readonly”>
适用范围:input单文本/多文本
(3)添加diabled 的属性
代码复制如下:
<input type = "text" name = "country" id= "country" value = "中国" diabled>
或者:<input type = "text" name = "country" id= "country" value = "中国" diabled =“diabled”>
或者:<input type = "text" name = "country" id= "country" value = "中国" diabled = "true">
适用范围:input单文本/多文本 select下拉列表