


Detailed explanation of the subtle differences between Readonly and Disabled
Both Readonly and Disabled can prevent users from changing the content in the form field, but there are still certain differences between them. The following is a detailed introduction to you.
Both Readonly and Disabled can prevent users from changing the contents of form fields. But there are slight differences between them, which are summarized as follows:
Readonly is only valid for input (text / password) and textarea, while disabled is valid for all form elements, but after the form element uses disabled, When we submit the form via POST or GET, the value of this element will not be passed out, but readonly will pass the value out (readonly accepts value changes and can return them, disable accepts changes but does not return data).
Generally common situations are:
A unique identification code is pre-filled in a form for the user, and the user is not allowed to change it, but the value needs to be passed when submitting. Its property should be set to readonly.
It is often encountered that when a user formally submits a form and needs to wait for information verification by the administrator, the user is not allowed to change the data in the form, but can only view it. Due to the large range of disabled elements, Therefore, disabled should be used at this time, but at the same time, it should be noted that the submit button should also be disabled. Otherwise, as long as the user presses this button, if there is no integrity check in the database operation page, the values in the database will be cleared. . If readonly is used instead of disabled in this case, it is still possible if there are only input (text/password) and textarea elements in the form. If there are other elements, such as select, the user can rewrite the value and press Press the Enter key to submit (Enter is the default submit trigger key)
We often use javascript to disable the submit button after the user presses the submit button. This can prevent the user from using the submit button in an environment with poor network conditions. The user repeatedly clicks the submit button causing data to be redundantly stored in the database.
The two attributes disabled and readonly have something in common. For example, if both are set to true, the form attribute cannot be edited. It is often easy to mix these two attributes when writing js code. In fact, they There are certain differences between them:
If the disabled of an input item is set to true, the form input item cannot obtain focus, and all user operations (mouse clicks and keyboard input, etc.) will affect the input item. Invalid, the most important point is that when the form is submitted, this form input will not be submitted.
Readonly is only for input items such as text input boxes that can input text. If set to true, the user just cannot edit the corresponding text, but can still focus, and when submitting the form, the input item will be used as A submission of the form.
For more detailed explanations of the subtle differences between Readonly and Disabled, please pay attention to the PHP Chinese website for related articles!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...
