首页 > Web开发 > 详细

html 文本框(text)不可用只读的多种实现方法

时间:2016-01-31 19:29:43      阅读:140      评论:0      收藏:0      [点我收藏+]
方法一: <input id= "File1" type= "text" disabled/> 不可用
方法二: <input id= "File1" type= "text" readonly/> 只读
方法三: <input id= "File1" type= "text" style="display:none"/> 隐藏(但占位置)
方法四: <input id= "File1" type= "text" style="visibility:hidden"/> 隐藏(不占位置)

有时候,我们希望表单中的文本框是只读的,让用户不能修改其中的信息,如使<input type="text" name="input1" value="中国"> 的内容,"中国"两个字不可以修改。实现的方式归纳一下,有如下几种。

方法1: onfocus=this.blur()

复制代码
代码如下:

<input type="text" name="input1" value="中国" onfocus=this.blur()>

方法2:readonly

复制代码
代码如下:

<input type="text" name="input1" value="中国" readonly>
<input type="text" name="input1" value="中国" readonly="true">

方法3: disabled

复制代码
代码如下:

<input type="text" name="input1" value="中国" disabled>

html 文本框(text)不可用只读的多种实现方法

原文:http://www.jb51.net/web/120333.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!