Home > Article > Web Front-end > How to invalidate all inputs in jquery
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");".
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.
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.
Open the test.html file in the browser and click the button to see the effect.
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!