How to make form input and other text boxes read-only and non-editable in HTML

How to make form input and other text boxes read-only and non-editable in HTML
Sometimes, we want the text boxes in the form to be read-only so that users cannot modify the information in them, such as making the content of <input type="text" name="input1" value="中国">, the word "中国" cannot be modified. To summarize, there are several ways to implement it.

Method 1: onfocus=this.blur() will lose focus when the mouse cannot be placed
<input type="text" name="input1" value="中国" onfocus=this.blur()>

Method 2: readonly
<input type="text" name="input1" value="中国" readonly>
<input type="text" name="input1" value="中国" readonly="true">

Method 3: disabled
<input type="text" name="input1" value="中国" disabled="true">

Complete example:

<input name="ly_qq" type="text" tabindex="2" onMouseOver="this.className='input_1'" onMouseOut="this.className='input_2'" value="123456789" disabled="true" readOnly="true" />

disabled="true" If this option is enabled, the text will become gray and cannot be edited.
readOnly="true" text will not change color and is not editable

CSS shielding input: <input style="ime-mode: disabled">

There are two methods: First: disabled="disabled". After this definition, the disabled input element is neither available nor clickable. Second: readonly="readonly" read-only fields cannot be modified. However, users can still use the tab key to switch to the field, and can select or copy its text;

<<:  TortoiseSvn Little Turtle Installation Latest Detailed Graphics Tutorial

>>:  Design Theory: Hierarchy in Design

Recommend

Mysql query the most recent record of the sql statement (optimization)

The worst option is to sort the results by time a...

Unicode signature BOM (Byte Order Mark) issue for UTF-8 files

I recently encountered a strange thing when debug...

How to configure tomcat server for eclipse and IDEA

tomcat server configuration When everyone is lear...

CSS style to center the HTML tag in the browser

CSS style: Copy code The code is as follows: <s...

Implementation of Docker deployment of Django+Mysql+Redis+Gunicorn+Nginx

I. Introduction Docker technology is very popular...

Summary of commonly used multi-table modification statements in Mysql and Oracle

I saw this question in the SQL training question ...

Mysql accidental deletion of data solution and kill statement principle

mysql accidentally deleted data Using the delete ...

Solution to Incorrect string value in MySQL

Many friends will report the following error when...

How to create a new user in CentOS and enable key login

Table of contents Create a new user Authorize new...

The most common mistakes in HTML tag writing

We better start paying attention, because HTML Po...

Some experience in building the React Native project framework

React Native is a cross-platform mobile applicati...

Analysis of MySQL Aborted connection warning log

Preface: Sometimes, the session connected to MySQ...

Use Xshell to connect to the Linux virtual machine on VMware (graphic steps)

Preface: I recently started to study the construc...