Home Web Front-end Front-end Q&A How to prohibit input in html5 input

How to prohibit input in html5 input

Feb 03, 2023 am 10:02 AM
html5 input

html5 Input prohibition implementation method: 1. Specify the input field as read-only and copyable through readonly; 2. Use disabled to realize that the disabled input element can be copied, but cannot receive focus; 3. By controlling the input The max length is 0; 4. Use "οnfοcus="this.blur();"" to realize that text cannot be input.

How to prohibit input in html5 input

The operating environment of this tutorial: Windows 10 system, HTML5 version, DELL G3 computer

html5 input How to prohibit input?

Input prohibition of input (forbidden to obtain focus) multiple methods and input limit number and length in html

Input prohibition of input (forbidden to obtain focus)

1: readonly stipulates that the input field is read-only and copyable. However, the user can use the Tab key to switch to the field, select it, receive focus, and select or copy its text.

<input type="text" value="禁止输入,可以使用Tab键切换到该字段" readonly="readonly">
Copy after login

2: disabled The disabled input element can be copied and cannot receive focus. After setting, the color of the text will turn gray. Cannot be used with .

<input type="text" value="可复制,不能接收焦点,字的颜色会变成灰" disabled="disabled">
Copy after login

3: Achieved by controlling the max length of the input to 0

<input type="text"  maxlength="0">
Copy after login

4: οnfοcus="this.blur();"onfocuse means focus, when you put the cursor on the text When typing in the box, it is focused, but "this.blur()" is added here. The function of blur is to remove the focus, that is, you cannot place the cursor on this text box. In other words, you cannot enter text.

<input type="text" value="去除聚焦,不能输入文本" onfocus="this.blur();">
Copy after login

Input input number and length limit

1.type='number' limits the input to numbers, and oninput determines the limit length (it is found that maxlength cannot be used after using type='number' )

<input class="inputs" type="number" value="只输入数字,长度11位" oninput="if(value.length>11)value=value.slice(0,11)"  />
Copy after login

2. Use maxlength to limit the length, and oninput to limit the input box to pure numbers

<input type="text" placeholder="请输入您的手机号" oninput = "value=value.replace(/[^\d]/g,&#39;&#39;)" maxlength="11">
Copy after login

a, onkeyup = "value=value.replace(/[^\d]/g,' ')"

There is a bug when using the onkeyup event. That is, in the Chinese input method state, if you press Enter directly after inputting Chinese characters, the letters

b and onchange = "value=value will be entered directly. .replace(/[^\d]/g,'')"

Use the onchange event. After inputting content, the result will only be obtained when the input loses focus. It cannot respond during input.

c, oninput = "value=value.replace(/[^\d]/g,'')"

Using the oninput event perfectly solves the above two problems. Test No other problems have occurred yet.

Recommended study: "HTML Video Tutorial"

The above is the detailed content of How to prohibit input in html5 input. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles