超简单的代码,
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> *{ padding: 0; margin: 0; } button{ width: 50px; height: 50px; font-size: 18px; } span{ width: 20px; display: inline-block; text-align: center; } </style> </head> <body> <button id="btn">-</button><span id="span"></span><button id="btn_1">+</button> </body> </html> <script src="https://code.jquery.com/jquery-3.3.1.min.js "></script> <script> var i=0; $('#span').text(i); $('#btn').click(function(){ if(i>=1){ i--; $('#span').text(i); } }); $('#btn_1').click(function(){ i++; $('#span').text(i); }); </script>