Home > Web Front-end > HTML Tutorial > Two ways to disable form controls in HTML: readonly and disabled_HTML/Xhtml_Webpage Production

Two ways to disable form controls in HTML: readonly and disabled_HTML/Xhtml_Webpage Production

WBOY
Release: 2016-05-16 16:36:53
Original
1821 people have browsed it

In the process of making web pages, we often use forms. But sometimes we want the controls on the form to be unmodifiable. For example, in a web page for changing passwords, the text box that displays the user name should be unmodifiable.

There are two disabling methods in HTML, they are:

1. Add the readonly='readonly' attribute to the control label
2. Add disabled to the control label ='disabled' attribute

Example:


Copy code
The code is as follows:





The two controls in the example cannot be modified. But they also have some differences!

From the literal meaning, we can know that the control using the readonly attribute is "read-only", and the control using disabled is "disabled". So what's the difference between them?

Read-only controls (controls that use the readonly attribute) cannot be modified by users with the mouse and keyboard, but programmers can use JavaScript to modify the name and value of the control when submitting the form. It will be submitted to the server, which means it is visible to the server.

Disabled controls (controls using the disabled attribute) not only cannot be modified by users with the mouse and keyboard, but are also invisible to the server, that is, their names and values ​​will not be submitted to the server when the form is submitted. , of course, programmers can also use javascript to modify its value.

This is their difference. After knowing the difference, we should know when to use which method. We must not be blind!
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