SoFunction
Updated on 2025-02-28

Summary of several methods to set text input boxes in form elements that cannot be edited

Code:

Copy the codeThe code is as follows:

<input type="text" value="fisker" onclick="alert();" onfocus="()" />

The input box cannot get focus and cannot be edited
The form can get values.
Can be copied.
It’s quite strange. I chose it all, but haven’t gained the focus yet?

2,readonly

Code:

<input type="text" value="fisker" onclick="alert();" readonly />

The input box is read-only. Cannot edit
The same form can get values.
It can also be copied.

3,disabled

Code:

Copy the codeThe code is as follows:

<input type="text" value="fisker" onclick="alert();" disabled />

The input box is grayed out and cannot be edited
Its value can be changed or obtained in JS, but the value is not submitted when committing.