<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<script src="jquery-3.2.1.min.js"></script>
</head>
<body>
<div id="main">
<table class="table table-striped">
<thead>
<tr>
<th scope="col">标号</th>
<th scope="col">名称</th>
<th scope="col">价格</th>
<th scope="col">数量</th>
<th scope="col">小计</th>
<th scope="col">操作</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">
<input type="checkbox" name="ck" class="ck">
</th>
<td>商品一号</td>
<td>9.91</td>
<td>
<button class="btn-up">+</button>
<input type="text" name="num" style="width: 30px" value="1">
<button class="btn-down">-</button>
</td>
<td class="subtotal">9.91</td>
<td><button class="btn-danger">删除</button></td>
</tr>
<tr>
<th scope="row">
<input type="checkbox" name="ck" class="ck">
</th>
<td>商品二号</td>
<td>9.9</td>
<td>
<button class="btn-up">+</button>
<input type="text" name="num" style="width: 30px" value="1">
<button class="btn-down">-</button>
</td>
<td class="subtotal">9.9</td>
<td><button class="btn-danger">删除</button></td>
</tr>
<tr>
<th scope="row">
<input type="checkbox" name="ck" class="ck">
</th>
<td>商品三号</td>
<td>100.23</td>
<td>
<button class="btn-up">+</button>
<input type="text" name="num" style="width: 30px" value="1">
<button class="btn-down">-</button>
</td>
<td class="subtotal">100.23</td>
<td><button class="btn-danger">删除</button></td>
</tr>
</tbody> </table>
<button id="qx">全选</button>
<button id="qbx">全不选</button>
<button id="fx">反选</button>
<button id="plsc">批量删除</button>
<p style="float: right">
总共购买<span id="counter">0</span> 件 ;支付总金额:<span id="total">0.00</span>¥
</p>
</div>
</body>
</html>
<script>
//加
$(".btn-up").click(function () {
var num = $(this).next().val();
num++;
var price = $(this).parent().prev().text();
var subTotal = price * num;
$(this).next().val(num);
$(this).parent().next().html(subTotal.toFixed(2));
$(this).parent().siblings(":first").find('.ck').prop("checked","checked");
computed();
});
//减
$(".btn-down").click(function () {
var num = $(this).prev().val();
if(num>1){
num--;
}
var price = $(this).parent().prev().text();
var subTotal = price * num;
$(this).prev().val(num);
$(this).parent().next().text(subTotal.toFixed(2)); computed();
});
//计算总金额
function computed(){
var total = 0;
var ele = $("input[name='ck']:checked");
var counter = ele.length;
ele.each(function (index,v) {
//
total += parseFloat( $(v).parent().parent().find('.subtotal').text());
});
$("#counter").html(counter);
$("#total").html(total).toFixed(2);
}
$(".ck").click(function () {
computed();
}); //全选
$("#qx").click(function () {
var ck = $("input[name='ck']");
for(var i=0;i<ck.length;i++){
ck[i].checked = true;
}
computed();
});
//全不选
$("#qbx").click(function () {
var ck = $("input[name='ck']");
for(var i=0;i<ck.length;i++){
ck[i].checked = false;
}
computed();
});
//反选
$("#fx").click(function () {
var ck = $("input[name='ck']");
for (var i=0;i<ck.length;i++){
if(ck[i].checked){
ck[i].checked = false;
}else{
ck[i].checked = true;
}
}
computed();
}); $(".btn-danger").click(function () {
$(this).parent().parent().empty();
}); $("#plsc").click(function () {
var ele = $("input[name='ck']:checked");
for(var i=0;i<ele.length;i++){
//$(ele[i]).parent().parent().remove();
$(ele[i]).parent().parent().remove();
}
computed();
}); </script>

  

最新文章

  1. 【无私分享:ASP.NET CORE 项目实战(第九章)】创建区域Areas,添加TagHelper
  2. IntelliJ IDEA 远程调试
  3. zabbix安装全过程
  4. 携手K2 BPM,华住酒店完美实现“互联网+”转型
  5. EXEL表格读取 按键精灵
  6. 细雨学习笔记:Jmeter上一个请求的结果作为下一个请求的参数--使用正则提取器
  7. source Insight注册码
  8. Oracle11g新特性之动态变量窥视
  9. JS数组追加数组采用push.apply的坑(转)
  10. 树莓派变成一个Web服务器: nginx + php + sqlite
  11. 第一百一十八节,JavaScript,动态加载脚本和样式
  12. Error Code: 1044. Access denied for user &#39;root&#39;@&#39;%&#39; to database
  13. .net aop 操作 切面应用 Castle.Windsor框架 spring 可根据接口 自动生成一个空的实现接口的类
  14. canvas高级篇(转载)移动元素
  15. java 实验 三 (1)
  16. ATM Mechine (概率DP)
  17. 关于Redis缓存数据库
  18. SpringMVC——SpringMVC简介
  19. 20155320 EXP8 Web基础
  20. 前端学习 -- Css -- 行间距

热门文章

  1. Vue 面试题
  2. JS实现new关键字的功能
  3. 微信小程序音频播放 InnerAudioContext 的用法
  4. 集合、Collection、list、set、HashSet
  5. Solution Set - 神奇 NOIP 模拟赛
  6. MyBatis功能点二:plugins插件使用
  7. 数据透视:Excel数据透视和Python数据透视
  8. 使用helm安装ingress,实现用域名的方式访问k8s内部应用
  9. 录毛线脚本,直接手写接口最简洁的LoadRunner性能测试脚本(含jmeter脚本)
  10. 巧用阿里云同步k8s.gcr镜像