《群星》水生種族擴充套件包推出 擁抱航海文明的生活
阿新 • • 發佈:2021-11-23
{__NOLAYOUT__} <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script type="text/javascript" src="__STATIC__/index_style/js/jquery-2.2.0.min.js" ></script> </head> <body> <table border="1"> <tr> <th> 全選/全不選<br> <input type="checkbox" id="choose"> </th> <th>商品圖片</th> <th>商品名稱</th> <th>商品單價</th> <th>商品數量</th> <th>商品小計</th> </tr> {volist name="data" id="v" key="k"} <tr> <td><input type="checkbox" class="cho"></td> <td><img src="__STATIC__/uploads/{$v.goods_img}" width="100" height="100"></td> <td>{$v.goods_name}</td> <td>{$v.goods_price}</td> <td> <button type="button" class="jia">+</button> <span>{$v.num}</span> <button type="button" class="jian">-</button> </td> <td class="count_price">{$v.count_price}</td> </tr> {/volist} </table> 總價:¥<span id="zongjia">0</span> </body> </html> <script> //多選框的點選事件 $('.cho').click(function(){ sum_price(); }) //計算總價 function sum_price(){ var sum=0 var obj = $("input[class=cho]"); for (var i = 0; i < obj.length; i++) { if(obj[i]['checked']){ sum+=Number($(obj[i]).parents("tr").find('.count_price').text()); } } $("#zongjia").text(sum); } //加號事件 $(".jia").click(function(){ //單價 var one_price = Number($(this).parent().prev().text()); //計算數量 var num = Number($(this).next()[0]['textContent']); num = num+1; //數量替換 $(this).next().text(num) //小計 xiaoji = num*one_price; //替換 $(this).parent().next().text(xiaoji) sum_price() }) //減號事件 $(".jian").click(function(){ //單價 var one_price = Number($(this).parent().prev().text()); //計算數量 var num = Number($(this).prev()[0]['textContent']); num = num-1 <= 0 ? 1: num-1; //數量替換 $(this).prev().text(num) //小計 xiaoji = num*one_price; //替換 $(this).parent().next().text(xiaoji) sum_price() }) </script>