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

发布时间:2022-04-12 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了html 文本框(text)不可用只读的多种实现方法脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
方法一: <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)不可用只读的多种实现方法全部内容,希望文章能够帮你解决html 文本框(text)不可用只读的多种实现方法所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。