Jquery method to change the type attribute of input: 1. Create an html file and introduce the jQuery file; 2. Create an input box with the input tag in the P tag, and set the default value of value to abcdefg, input tag The ID is tuiput; 3. Create a button with the button tag and bind the onclick event; 4. Use the "$('#tuinput').attr('type','password');" syntax.
The operating system of this tutorial: Windows 10 system, jQuery3.6.0 version, Dell G3 computer.
jquery changes the type attribute of input through the "attr()" method:
1. Create a new html file, name it test.html, and introduce it in the head jQuery file
2. In the html file, within the p tag, use the input tag to create an input box, and set its default value to abcdefg
3. In the test.html file, set the id attribute value of the input tag to tuinput, which is mainly used to obtain the input object through this id below
4. In the test.html file, use the button tag to create a button with the button name "Change the type attribute of input"
5. In test. In the html file, bind the onclick click event to the button button. When the button is clicked, the editype() function is executed
#6. In the js tag, create editype() Function, within the function, obtain the input object through id (tuinput), use the attr() method to change the type attribute value to password
7. Open the html file in the browser, Click the button to see the effect
The above is the detailed content of How to change the type attribute of input in jquery. For more information, please follow other related articles on the PHP Chinese website!