Home > Article > Web Front-end > How to modify the type attribute in jquery
In jquery, you can use the attr() method to modify the type attribute of the element. This method can set the attribute value of the selected element. The syntax is "$(selector).attr("type","new Value ")" or "$(selector).attr({type:new value})".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
In jquery, by obtaining the input object, the type can be changed using the attr() method. Syntax:
$(selector).attr("type","新值"); $(selector).attr({type:新值});
Example:
In the p tag, use the input tag to create an input box and set its value default value to abcdefg.
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.
In the test.html file, use the button tag to create a button with the button name "Change the type attribute of the input".
In the test.html file, bind the onclick click event to the button button. When the button is clicked, the editype() function is executed.
In the js tag, create the editype() function. Within the function, obtain the input object through id(tuinput), and use the attr() method to change the type attribute value to password. .
Open the test.html file in the browser and click the button to see the effect.
[Recommended learning: jQuery video tutorial, web front-end video】
The above is the detailed content of How to modify the type attribute in jquery. For more information, please follow other related articles on the PHP Chinese website!