Get the App
SLTechnology News&Howtos  ›  Development  › 

How does jquery make the text box disable input

Shulou Source: shulou.com Published: 2022-06-01 05:19:12 10月02日 Update

This article mainly explains the "jquery how to make the text box prohibit input", the text explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "jquery how to make the text box prohibit input" bar!

Prohibited text box input methods: 1, the use of "$(" textarea "). Attr (" disabled "," disabled ");" statement prohibition; 2, the use of "$(" textarea "). Attr (" readonly "," readonly ");" statement prohibition.

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

If you want the text box to disable input, you can set the disabled or readonly property to the text box so that it is not editable or read-only.

The method of letting the text box prohibit input by jquery

Method 1: use the attr () method to set the disabled property

Syntax:

$("textarea") .attr ("disabled", "disabled"); $("textarea") .attr ("disabled", "true")

Example:

$(document) .ready (function () {$("button") .click (function () {$("textarea") .attr ("disabled", "disabled"); / / $("textarea") .attr ("disabled", "true") );})

Make textarea uneditable

Method 2: use the attr () method to set the readonly property

Syntax:

$("textarea") .attr ("readonly", "readonly"); $("textarea") .attr ("readonly", "true")

Example:

$(document) .ready (function () {$("button") .click (function () {/ / $("textarea") .attr ("readonly", "readonly"); $("textarea") .attr ("readonly", "true") );})

Let textarea disable input

Thank you for your reading, the above is the content of "jquery how to make the text box prohibit input". After the study of this article, I believe you have a deeper understanding of how jquery makes the text box prohibit input, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Text input methods properties learning content examples statements grammar that is ideas situations tutorials articles more versions environment computers knowledge knowledge points Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Huawei Xiaomi Linux MariaDB