Home >Web Front-end >HTML Tutorial >How to realize that HTML text box cannot modify its content

How to realize that HTML text box cannot modify its content

小云云
小云云Original
2017-12-01 11:12:323426browse

In this article, we will share with you a basic knowledge: HTML method to realize that the text box is read-only and cannot modify the content. I hope it will be helpful to everyone.

<!--方法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 content is the HTML method to realize that the text box is read-only and cannot modify the content. Although it is very simple, it is indeed a practical little method. I hope it will be helpful to everyone.

Related recommendations:

jQuery implements the function of setting and removing the default value of the text box

The input text box is non-editable in html Method

Brief description of the implementation method of simultaneous input into two text boxes

The above is the detailed content of How to realize that HTML text box cannot modify its content. 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