Home  >  Article  >  Web Front-end  >  How to modify the step attribute in jquery

How to modify the step attribute in jquery

WBOY
WBOYOriginal
2022-05-18 10:18:461679browse

Jquery method to modify the step attribute: 1. Use "$("The element that needs to modify the step attribute")" to obtain the specified element object; 2. Use "element object.attr("step","step The modified value ");" can modify the step attribute value of the specified element.

How to modify the step attribute in jquery

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

How to modify the step attribute in jquery

1. Use $() to obtain the specified element object

$ is a commonly used callback function in JQuery. Defined as "select", the English abbreviation of selector

$ is actually another name for jQuery, and jQuery is a function provided by the jQuery library.

This function can search and select elements in the html document based on the parameters in (). () can not only be IDs, but also various selectors

For example:

$(document) is to select the entire document object

2. Use the attr method to modify the step attribute

attr() method sets or returns the selected Element attributes and values.

When this method is used to return an attribute value, the value of the first matching element is returned.

When this method is used to set attribute values, one or more attribute/value pairs are set for the matching element.

Syntax

Return the value of the attribute:

$(selector).attr(attribute)

Set the attribute and value:

$(selector).attr(attribute,value)

The example is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>123</title>
<script src="js/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("input").attr("step","500");
});
});
</script>
</head>
<body>
<form action="demo-form.php">
  <input type="number" name="points" step="3">
</form>
<br>
<button>为元素修改step属性</button>
</body>
</html>

Output result:

How to modify the step attribute in jquery

Recommended related video tutorials: jQuery video tutorial

The above is the detailed content of How to modify the step 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