" or ""."/> " or "".">

Home >Web Front-end >HTML Tutorial >How to set read-only in html text box

How to set read-only in html text box

青灯夜游
青灯夜游Original
2021-05-14 15:09:569834browse

In HTML, you can achieve read-only function by setting the readonly attribute to the text box element (input or textarea), the syntax is "" or "

How to set read-only in html text box

The operating environment of this tutorial: Windows 7 system, HTML5 version, Dell G3 computer.

In html, there are two types of text box elements:

  • input

  • textarea

If you want to make the text box read-only, you only need to set the readonly attribute to the text box element.

The readonly property is a Boolean property.

The readonly attribute specifies that the text area is read-only.

In a read-only text area, the content cannot be modified, but the user can switch to the control through the tab key and select or copy the content.

You can set the readonly attribute to resume the user's use of the text area until certain conditions are met (such as selecting a check box). You can then use JavaScript to remove the value of the readonly attribute to make the text area editable.

Example:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
  </head>
  <body>
  	<input type="text" value="测试文本"/><br>
  	<input type="text" value="测试文本" readonly="readonly"/>
  	<hr>
  	<textarea>测试文本</textarea><br>
  	<textarea readonly>测试文本</textarea>
  </body>
</html>

How to set read-only in html text box

How to set read-only in html text box

##Recommended tutorial: "

html video tutorial

The above is the detailed content of How to set read-only in html text box. 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