Home > Article > Web Front-end > How to remove required attribute in jquery
In jquery, you can use the removeAttr() method to remove the required attribute of an element. This method is used to remove one or more attributes from the selected element. Just set the parameter to "required". , the syntax is "specify element object.removeAttr("required");".
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
The required attribute is a Boolean attribute. The
required attribute specifies that the input fields must be filled in before submitting the form.
Note: The required attribute applies to the following input types: text, search, url, tel, email, password, date pickers, number, checkbox, radio and file.
The syntax is:
<input required>
removeAttr() method removes one or more attributes from the selected element.
Syntax
$(selector).removeAttr(attribute)
attribute required. Specifies one or more properties to remove. To remove several properties, separate the property names with spaces.
The example is as follows:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="123/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("input").removeAttr("required"); }); }); </script> </head> <body> <form action="demo-form.php"> Username: <input type="text" name="usrname" required> <input type="submit"> </form> <button>去除required属性 </button> </body> </html>
Output result:
Before clicking the remove attribute button:
Click to remove the attribute You can click directly after the button.
Video tutorial recommendation: jQuery video tutorial
The above is the detailed content of How to remove required attribute in jquery. For more information, please follow other related articles on the PHP Chinese website!