Home  >  Article  >  Web Front-end  >  How to set text box to read-only in css

How to set text box to read-only in css

王林
王林Original
2021-06-08 16:15:195388browse

The way to set the text box to read-only in css is to add the readonly attribute to the input text box. The readonly attribute is a Boolean attribute that specifies that the input field is read-only.

How to set text box to read-only in css

The operating environment of this article: windows10 system, css 3, thinkpad t480 computer.

The readonly attribute is a Boolean attribute in HTML, which is used to specify that the input field is read-only.

We know that read-only fields cannot be modified, but users can still use the tab key to switch to the field, and can also select or copy its text.

The readonly attribute prevents users from modifying the value until certain conditions are met (such as a checkbox being selected). Then, you need to use JavaScript to eliminate the readonly value and switch the input field to an editable state.

Note: All major browsers support the readonly attribute.

Example:

HTML form with read-only input fields.

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title></title> 
</head>
<body>

<form action="demo_form.php">
  Email: <input type="text" name="email"><br>
  Country: <input type="text" name="country" value="Norway" readonly><br>
  <input type="submit" value="提交">
</form>

</body>
</html>

Running results:

How to set text box to read-only in css

Related video sharing: css video tutorial

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