How to modify the value of button in jquery

青灯夜游
Release: 2022-03-18 13:58:18
Original
6178 people have browsed it

Jquery method to modify button value: 1. Use html() function, syntax "$("button").html("New value to be set");"; 2. Use text() function , the syntax is "$("button").text("New value to be set");".

How to modify the value of button in jquery

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

jquery changes the value of the button

Method 1: Use the html() method

html () method sets or returns the content of the selected element (innerHTML).

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<script src="js/jquery-1.10.2.min.js"></script>
		<script type="text/javascript">
			$(document).ready(function() {
				$("button").click(function() {
					$("button").html("修改好了,新值");
				});
			});
		</script>
	</head>

	<body>
		<button>修改按钮的值</button>
	</body>
</html>
Copy after login

How to modify the value of button in jquery

Method 2: Use text() method

text() method sets or returns the text content of the selected element.

When this method is used to return content, the text content of all matching elements is returned (HTML tags will be removed).

When this method is used to set content, the content of all matching elements is rewritten.

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<script src="js/jquery-1.10.2.min.js"></script>
		<script type="text/javascript">
			$(document).ready(function() {
				$("button").click(function() {
					$("button").text("设置好新值了");
				});
			});
		</script>
	</head>

	<body>
		<button>修改按钮的值</button>
	</body>
</html>
Copy after login

How to modify the value of button in jquery

[Recommended learning: jQuery video tutorial, web front-end

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