Home >Web Front-end >Front-end Q&A >How to modify the value of button in jquery
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");".
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>
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>
[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!