Home  >  Article  >  Web Front-end  >  How to implement HTML text box that can only be read but cannot be modified

How to implement HTML text box that can only be read but cannot be modified

巴扎黑
巴扎黑Original
2018-05-15 16:12:562649browse

This article introduces to you through example code how to implement HTML text boxes that are read-only and cannot modify the content. Friends who need it can refer to it

No more nonsense, I will directly post the code for you. The specific code is as follows:

 <!--方法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="true">

The above is the detailed content of How to implement HTML text box that can only be read but cannot be modified. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn