Home >Web Front-end >Front-end Q&A >How to set read-only tags in html5

How to set read-only tags in html5

WBOY
WBOYOriginal
2021-12-31 10:08:501661browse

In HTML5, you can use the readonly attribute to set a read-only and unchangeable tag. This attribute is used to set the specified tag field to be read-only. It can be selected and copied but cannot be modified. The syntax is "readonly="readonly "".

How to set read-only tags in html5

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

html5How to set a read-only tag that cannot be changed

The readonly attribute specifies that the input field is read-only.

Read-only fields cannot be modified. However, users can still tab to the field and 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.

The readonly attribute can be used with or .

The example is as follows:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<p>Country:<input type="text" name="country" 
  value="China" readonly="readonly" /></p>
</body>
</html>

Output result:

How to set read-only tags in html5

Recommended tutorial: "html video tutorial"

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