html代码

<!--shoppingCar start-->
  <table id="TB">
   <tr>
    <td colspan="7" class="title">
     <div class="img_box">
      <div class="logo_box">
       <img src="img/jdlogo-201708-@1x.png" class="logo" />
      </div>
      <div class="img_font">购物车</div>
     </div>
     <div class="input_box">
      <input type="text" placeholder="自营" class="search" />
      <input type="button" value="搜索" class="button" />
     </div>
    </td>
   </tr>
   <tr >
    <td class="first_row">
     <input type="checkbox" id="qx"/>全选
    </td>
    <td class="second_row">商品图片</td>
    <td class="third_row">商品描述</td>
    <td class="fourth_row">单价</td>
    <td class="fifth_row">数量</td>
    <td class="sixth_row">小计</td>
    <td class="seventh_row">操作</td>
   </tr>
   <tr class="checked">
    <td class="first_row">
     <input type="checkbox" name="Put"/>
    </td>
    <td class="second_row">
     <img src="img/img_01.jpg" />
    </td>
    <td class="third_row">丹慕妮尔2016秋装新品</td>
    <td class="fourth_row">¥ <input value="199.00" style="width: 80px;"/></td>
    <td class="fifth_row"><button class="Jia">+</button><input value="1"class="Zhi"style="width: 80px;height: 20px;text-align: center;"/><button class="jian">-</button></td>
    <td class="sixth_row">¥ <input class="Xiaoji" value="199.00"style="width: 80px;"/></td>
    <td class="seventh_row"><span class="shanchu">删除</span></td>
   </tr>
   <tr tr class="checked">
    <td class="first_row">
     <input type="checkbox" name="Put"/>
    </td>
    <td class="second_row">
     <img src="img/img_02.jpg" />
    </td>
    <td class="third_row">丹慕妮尔2016秋装新品</td>
    <td class="fourth_row">¥ <input  value="38.00" style="width: 80px;"/></td>
    <td class="fifth_row"><button class="Jia">+</button><input value="1" class="Zhi"style="width: 80px;height: 20px;text-align: center;"/><button class="jian">-</button></td>
    <td class="sixth_row">¥  <input class="Xiaoji"   value="38.00"style="width: 80px;"/></td>
    <td class="seventh_row"><span class="shanchu">删除</span></td>
   </tr>
   <tr tr class="checked">
    <td class="first_row">
     <input type="checkbox" name="Put"/>
    </td>
    <td class="second_row">
     <img src="img/img_03.jpg" />
    </td>
    <td class="third_row">丹慕妮尔2016秋装新品</td>
    <td class="fourth_row">¥ <input value="277.88" style="width: 80px;"/></td>
    <td class="fifth_row"><button class="Jia">+</button><input value="1" class="Zhi"style="width: 80px;height: 20px;text-align: center;"/><button class="jian">-</button></td>
    <td class="sixth_row">¥  <input class="Xiaoji"  value="277.88"style="width: 80px;"/></td>
    <td class="seventh_row"><span id="del" class="shanchu">删除</span></td>
   </tr>
   <tr class="end">
    <td colspan="7" class="end">
     <div class="changed">
      <input type="checkbox"id="fx" />反选    
     </div>
     <div class="del">
      <input id="SHAN" type="button" value="删除已选" />    
     </div>
     <div class="clearing"> 
      <div class="font">已选择<span id="totalAmount">0</span>件商品&nbsp;总价¥<span id="totalPrice">0.00</span></div>
      <input type="button" value="去结算" />
     </div>
    </td>
   </tr>
  </table>
  <!--shoppingCar end-->

js代码

//全选
$("#qx").click(function(){
 $("[name='Put']").prop("checked",$("#qx").prop("checked"));
 show();
 zong();
});
//反选
$("#fx").click(function(){
 $("[name='Put']").each(function(){
  $(this).prop("checked",!$(this).prop("checked"))
 })
 show();
 zong();
});
//单选
$("[name='Put']").click(function(){
 show();
 zong();
})
//方法
function show(){
 $("[name='Put']").each(function(){
 if ($("[name='Put']:checked").length==$("[name='Put']:checkbox").length) {
  $("#qx").prop("checked",true);
 } else{
  $("#qx").prop("checked",false);
 }
 })
}
//删除
$(".shanchu").click(function(){
 $(this).parents('.checked').remove();
 zong();
});
//数量的增加/减少
$(".Jia").click(function(){
 $(this).next().val(parseInt($(this).next().val())+1);
 $(this).parent().next().find(".Xiaoji").val(($(this).next().val()*$(this).parent().prev().find("input").val()).toFixed(2));
 zong();
});
$(".jian").click(function(){
 if($(this).prev().val()>1){
  $(this).prev().val(parseInt($(this).prev().val())-1);
  $(this).parent().next().find(".Xiaoji").val(($(this).prev().val()*$(this).parent().prev().find("input").val()).toFixed(2))
 }
 zong();
});
//删除已选
$("#SHAN").click(function(){
 $("[name='Put']").each(function(){
  if($(this).prop("checked")){
   $(this).parents(".checked").remove();
  }
 });
 zong();
});
//总价
function zong(){
 var totalA=0;
 var totalP=0;
 $("[name='Put']").each(function(){
  if ($(this).prop('checked')) {
   var shul=parseFloat($(this).parent().siblings(".fifth_row").find(".Zhi").val());
   totalA+=shul;
   var qian=parseFloat($(this).parent().siblings(".sixth_row").find(".Xiaoji").val());
   totalP+=qian;
  }
 });
 $("#totalAmount").text(totalA);
 $("#totalPrice").text(totalP);
};
 
 
 

jQuery 购物车的更多相关文章

  1. JQuery购物车多物品数量的加减+总价计算

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. jQuery 购物车鼠标经过出现下拉框的做法

    这一段时间在学习web前端,最近学了jQuery库,深感其强大,下面通过写购物车的下拉框做法,把自己的理解和大家交流一下,欢迎各位大神指点指正,废话不多说,开始正题: 购物车html: <!-- ...

  3. Jquery购物车jsorder改进版,支持后台处理程序直接转换成DataTable处理

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  4. jQuery购物车

    效果图 HTML代码:(非表格方式) <div class="nav2"> <input type="checkbox" class=&quo ...

  5. jquery购物车添加功能

    <html> <head> <meta charset="UTF-8"> <title></title> <scr ...

  6. jQuery 购物车案例

    h1 { text-align: center; } .cart { width: 1200px; height: 600px; margin: 0 auto; border: 1px solid # ...

  7. jquery 购物车飞入效果

    github https://github.com/amibug/fly demo https://github.com/amibug/fly

  8. jquery购物车计算总价

    //计算总价 function cartTotal(){ var total = 0; //循环计算的列,选中计算的数量和价格 //accAdd为精BigDecimal准计算方法 $.each($(& ...

  9. jquery购物车全选,取消全选,计算总金额

    这是html代码 <div class="gwcxqbj"> <div class="gwcxd center"> <div cl ...

随机推荐

  1. 100-days: twenty-three

    Title: The surprising connection between single women and gentrification connection n.连接,联系,关系:连接点; ...

  2. java 中拿项目路径

    public class ItemPathInterceptor extends HandlerInterceptorAdapter { @Override public boolean preHan ...

  3. Ubuntu ROS

    设置你的sources.list 将电脑设置为接受来自packages.ros.org的软件 sudo sh -c 'echo "deb http://packages.ros.org/ro ...

  4. java基础 ---- 一维数组

    为什么要使用数组: 因为不使用数组计算多个变量的时候太繁琐,不利于数据的处理. --------   数组也是一个变量,是存储一组相同类型的变量 声明一个变量就是在内存中划出一块合适的空间 声明一个数 ...

  5. Tomcat开启本地库(Apache Tomcat Native Library)支持

    操作系统环境:Ubuntu 17 amd64位 软件环境:Tomcat 9 tomcat安装位置:/opt/tomcat JDK:1.8.144 64位  安装步骤: 1:编译安装 cd /opt/t ...

  6. java常用集合浅层解析-面试必备

    ArrayList 1.动态数组 2.线程不安全 3.存储空间连续 4.查询快,添加删除慢 构造方法 /** + Shared empty array instance used for defaul ...

  7. View操作 swift

    //创建View let view1 =UIView() let view2 =UIView(frame: CGRectMake(,, ,)) let view3 =UIView(frame: CGR ...

  8. 201621123002《java程序设计》第九周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 1.2 选做:收集你认为有用的代码片段 //功能需求:将所有大于5的生成一个新的List对象 List lis ...

  9. 堆&栈的理解(转)

    (摘自:http://www.cnblogs.com/likwo/archive/2010/12/20/1911026.html) C++中堆和栈的理解 内存分配方面: 堆: 操作系统有一个记录空闲内 ...

  10. 密码与安全新技术专题之WEB应用安全

    学号 2018-2019-2 <密码与安全新技术专题>第1周作业 课程:<密码与安全新技术专题> 班级: 1892 姓名: 李熹桥 学号:20189214 上课教师:谢四江 上 ...