Home > Web Front-end > Front-end Q&A > What is the syntax for read only and disabled in html5

What is the syntax for read only and disabled in html5

WBOY
Release: 2022-01-23 16:03:13
Original
2344 people have browsed it

In HTML5, the syntax for read-only and disabled is "" and ""; the readonly attribute is used to specify the input field Being read-only, the disabled attribute specifies that the element should be disabled.

What is the syntax for read only and disabled in html5

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

What is the syntax for read-only and disabled in html5

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 .

Syntax

<input readonly="value">
Copy after login

The disabled attribute specifies that the input element should be disabled.

A disabled input element is neither available nor clickable. The disabled attribute can be set until some other condition is met (such as a checkbox being selected, etc.). Then, you need to use JavaScript to remove the disabled value and switch the value of the input element to available.

Note: The disabled attribute cannot be used with .

Grammar

<input disabled="value">
Copy after login

The example is as follows:

<html>
<body>
<form action="/example/html/form_action.asp" method="get">
  <p>正常的input:<input type="text" name="fname" /></p>
  <p>禁用input: <input type="text" name="lname" disabled="disabled" /></p>
    <p>只读input:<input type="text" name="country" 
  value="China" readonly="readonly" /></p>
</form>
<p>请在提交按钮上单击,输入会发送到服务器上名为 "form_action.asp" 的页面。</p>
</body>
</html>
Copy after login

Output result:

What is the syntax for read only and disabled in html5

Recommended tutorial: "html Video tutorial

The above is the detailed content of What is the syntax for read only and disabled in html5. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template