數量選擇器 1 2 3 <button type="button" class="reduce">-</button> <span>0</span> <button type="button" class="add">+</button> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 //數量初始值 let num = 0; $(".reduce").click(function(){ //每次點擊數量-1,num = num - 1; num-=1; $("span").text(num); }); $(".add").click(function(){ //每次點擊數量+1,num = num + 1; num+=1; $("span").text(num); }); javaScript 其他相關 【JS】加入聲音效果 【JS】jQuery實作滾動頁面頁籤變換 【JS】jQuery實作點擊錨點滑動至該區塊 【JS】jQuery判斷式 【JS】jQuery處理物件與陣列