Home > Web Front-end > Front-end Q&A > How to set text box read-only in javascript

How to set text box read-only in javascript

藏色散人
Release: 2022-01-18 15:05:43
Original
4777 people have browsed it

How to set the text box read-only in javascript: 1. Set by "onfocus=this.blur()"; 2. Set by "readonly"; 3. Set the text box read-only by "disabled".

How to set text box read-only in javascript

The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.

How to set the text box read-only in javascript?

javascript: How to make the form text box read-only and non-editable

Sometimes, we want the text box in the form to be read-only, so Users cannot modify the information. For example, in the content of , the word "China" cannot be modified. To summarize, the implementation methods are as follows.

Method 1:

onfocus=this.blur()

<input type="text" name="input1" value="中国" onfocus=this.blur()>
Copy after login

Method 2:

readonly

<input type="text" name="input1" value="中国" readonly>
<input type="text" name="input1" value="中国" readonly="true">
Copy after login

Method 3:

disabled

<input type="text" name="input1" value="中国" disabled>
Copy after login

Recommended study: "js Basic Tutorial"

The above is the detailed content of How to set text box read-only in javascript. 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
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template