How to modify the step attribute in jquery

WBOY
Release: 2022-05-18 10:18:46
Original
1692 people have browsed it

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)
Copy after login

Set the attribute and value:

$(selector).attr(attribute,value)
Copy after login

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>
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!