Home  >  Article  >  Web Front-end  >  How to remove required attribute in jquery

How to remove required attribute in jquery

WBOY
WBOYOriginal
2022-06-06 18:34:032636browse

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");".

How to remove required attribute in jquery

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How to remove the required attribute in jquery

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:

How to remove required attribute in jquery

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!

Statement:
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