Home > Web Front-end > JS Tutorial > body text

How to invalidate all inputs in jquery

WBOY
Release: 2021-12-07 15:53:38
Original
3236 people have browsed it

Method: 1. Use the "$(input element)" statement to obtain all input element objects; 2. Use the prop() method and disabled attribute to invalidate the obtained input elements. The syntax is "input Element object.prop("disabled","disabled");".

How to invalidate all inputs in jquery

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How does jquery invalidate all inputs

In jquery, by obtaining the text box object, use the prop() method to set the disabled attribute to disabled, you can make the text box unavailable. The following example explains how to set the text box to be unavailable in jquery.

The example is as follows:

1. Create a new html file, named test.html, to explain how jquery sets the text box to be unavailable. Within the p tag, use the input tag to create a text input box for input of text content. Set the id attribute of the input tag to testinput, which is mainly used to obtain the input object through the id below. Use the button tag to create a button with the name "Set text box unavailable". Bind the onclick click event to the button button. When the button is clicked, the setdis() function is executed.

How to invalidate all inputs in jquery

2. In the js tag, create the setdis() function. Within the function, use the $ symbol to obtain the input object through id (testinput), and use the prop() method to set it. The disabled attribute of input is disabled, making the text box unavailable.

How to invalidate all inputs in jquery

Open the test.html file in the browser and click the button to see the effect.

How to invalidate all inputs in jquery

How to invalidate all inputs in jquery

Summary:

1. Create a test.html file.

2. In the file, within the p tag, use the input tag to create a text input box and create a button button to trigger the execution of the js function.

3. Create a function in the js tag. Within the function, obtain the input object and use the prop() method to set the disabled attribute of the input to disabled, thereby making the text box unavailable.

Note:

In jquery, the prop() method is mainly used to set or return the attributes and values ​​of the selected element.

Recommended related video tutorials: jQuery video tutorial

The above is the detailed content of How to invalidate all inputs in jquery. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!