本篇文章分享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不可用只读的多种实现方法的详细内容,更多请关注php中文网其它相关文章!
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号