Home > Common Problem > How to change the type attribute of input in jquery

How to change the type attribute of input in jquery

尊渡假赌尊渡假赌尊渡假赌
Release: 2023-05-30 11:29:06
Original
3011 people have browsed it

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.

How to change the type attribute of input in jquery

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

How to change the type attribute of input in jquery

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

How to change the type attribute of input in jquery

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

How to change the type attribute of input in jquery

4. In the test.html file, use the button tag to create a button with the button name "Change the type attribute of input"

How to change the type attribute of input in jquery

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

How to change the type attribute of input in jquery

#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

How to change the type attribute of input in jquery

7. Open the html file in the browser, Click the button to see the effect

How to change the type attribute of input in jquery

How to change the type attribute of input in jquery

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!

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