在jQuery中,你可以使用 .text()
方法来设置 <button>
元素的文字。下面是一个简单的示例,演示了如何使用 jQuery 来更改按钮的文字:
$('#myButton').text('新文字');
完整示例代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="www.02405.com">
<title>jQuery 设置 Button 文字</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<button id="myButton">原始文字</button>
<script>
$(document).ready(function(){
// 设置按钮的文字
$('#myButton').text('新文字');
});
</script>
</body>
</html>