实现了:第一件商品的加减
实现了:全选/全不选(使用prop而不是attr)
实现了:删除(遮罩层)

未实现:第二件商品的删除
未实现:小计及应付款额的初始化(写死的)

计算小数乘法时,要先乘100

<!DOCTYPE html>
<html> <head>
<meta charset="UTF-8">
<title></title>
</head>
<style>
.div1 {
border: 1px solid gainsboro;
width: 950px;
height: 60px;
} .div-checkbox,
.div-goods,
.div-amount,
.div-unit-price,
.div-price,
.div-del {
border: 1px solid;
width: 60px;
height: 20px;
padding: 20px;
float: left;
text-align: center;
} .div-price {
width: 100px;
} .div-goods {
width: 140px;
} .div-amount {
width: 140px;
} .div-unit-price {
width: 50px;
} .div-total-price {
border: 1px solid gainsboro;
width: 950px;
height: 60px;
text-align: right;
} .div-submit {
width: 950px;
text-align: right;
} div#cover {
/*遮罩层*/
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 1000px;
z-index: 100;
display: none;
background-color: grey;
} div#prompt {
/*弹窗*/
border: 2px solid yellow;
display: none;
position: fixed;
top: 100px;
left: 500px;
z-index: 101;
width: 300px;
height: 200px;
}
</style>
<script type="text/javascript" src="js/jquery-1.11.0.min.js"></script>
<script>
$(function() { //全选
var i = 0;
$(".allPic").click(function() {
i++;
if (i % 2 != 0) {
//此处用attr则只能选中/取消一次
$(".cls-checked").prop("checked", true);
} else {
$(".cls-checked").prop("checked", false);
}
}); //通过name获取某一商品的按钮
$("input[name='btn1']").click(function() {
//数量
var _amount = parseInt($("#id-txt-amount1").val());
if ($(this).val() == "+") {
_amount++;
} else if ($(this).val() == "-") {
if (_amount == 1) {
//必须买!
return;
}
_amount--;
}
$("#id-txt-amount1").attr("value", _amount); // 本商品的总价
var _unitPrice = $("#id-unit-price1").html();
var _thisPrice = parseFloat(_unitPrice * 100 * _amount / 100).toFixed(2);
$("#id-price1").html(_thisPrice); // 总价
var _otherPrice = $("#id-price2").html();
var _totalPrice = parseFloat(_thisPrice + _otherPrice).toFixed(2);
$("#id-total-price").html(_totalPrice);
}); //删除一条
$(".div-del a").click(function() {
showPrompt(this);
});
}); function showPrompt(obj) {
$("#cover").css("display", "block");
// 10毫秒内透明度降为0.5
$("#cover").fadeTo(10, 0.5);
$("#prompt").css("display", "block");
$("#prompt a").click(function() {
$("#cover").css("display", "none");
$("#prompt").css("display", "none");
return;
});
$("#prompt input").click(function() {
$("#cover").css("display", "none");
$("#prompt").css("display", "none");
$(obj).each(function() {
$(obj).parent("div").parent("div").remove();
});
});
}
</script> <body>
<!--遮罩层-->
<div id="cover"></div>
<!--弹窗-->
<div id="prompt">
<div style="width: 100%;height: 20px;text-align: right;background-color: gray;">
<a href="#">关闭</a>
</div>
<div style="text-align: center;background-color: white;width: 300px;height: 180px;line-height: 100px;">
确认删除吗?
<br />
<input type="button" value="确定" />
</div>
</div>
<!--表头------------------------------------------------------->
<div class="div1">
<div class="div-checkbox">
<input type="checkbox" class="allPic"><b>全选</b></input>
</div>
<div class="div-goods"><b>项目</b></div>
<div class="div-amount"><b>数量</b></div>
<div class="div-unit-price"><b>单价</b></div>
<div class="div-price"><b>小计</b></div>
<div class="div-del"></div>
</div>
<!--第一行------------------------------------------------------->
<div class="div1">
<div class="div-checkbox"><input type="checkbox" class="cls-checked" /></div>
<div class="div-goods">
A </div>
<div class="div-amount">
<input type="button" value="-" name="btn1" />
<input type="text" size="2" value="1" id="id-txt-amount1" />
<input type="button" value="+" name="btn1" />
</div>
<div class="div-unit-price">
¥<span id="id-unit-price1">9.90</span>
</div>
<div class="div-price">¥<span id="id-price1">2.00</span></div>
<div class="div-del"><a href="#">删除</a></div>
</div>
<!--第二行(未实现加减)------------------------------------------------------->
<div class="div1">
<div class="div-checkbox"><input type="checkbox" class="cls-checked" /></div>
<div class="div-goods">
B
</div>
<div class="div-amount">
<input type="button" value="-" class="btn2" />
<input type="text" size="2" value="1" id="id-txt-amount2" />
<input type="button" value="+" class="btn2" />
</div>
<div class="div-unit-price">
¥<span id="id-unit-price2">2.00</span>
</div>
<div class="div-price">¥<span id="id-price2">2.00</span></div>
<div class="div-del"><a href="#">删除</a></div>
</div> <div class="div-total-price">应付款额: ¥
<span id="id-total-price">11.90</span>
</div>
<div class="div-submit">
<input type="submit" />
</div>
</body> </html>

JS购物车编辑的更多相关文章

  1. JQuery案例:购物车编辑

    购物车编辑 实现了:商品的加减,总价的变动 实现了:全选/全不选(使用prop而不是attr) 实现了:删除(遮罩层) <html> <head> <meta chars ...

  2. js获取编辑框游标的位置

    代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...

  3. 简单实用angular.js购物车功能

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. Eclipse中jsp、js文件编辑时,卡死现象解决汇总

    使用Eclipse编辑jsp.js文件时,经常出现卡死现象,在网上百度了N次,经过N次优化调整后,卡死现象逐步好转,具体那个方法起到作用,不太好讲.将所有用过的方法罗列如下: 1.取消验证 windo ...

  5. js购物车计算价格

    <!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta nam ...

  6. jira7通过全局js给编辑区自定义快捷键【原】

    jira7编辑区自定义快捷键 本文主要描述了jira7如何通过添加全局js引用,给文本编辑区自定义快捷键用以快速填充模板内容. jira 3/4/5可参考官方api https://developer ...

  7. vue.js购物车

    vue.js https://cn.vuejs.org/v2/guide/ 简单购物车 <html> <head> <script src="https://c ...

  8. js 购物车的实现

    购物车原理:创建一个构造函数,把涉及到的项目写成方法,然后把这些方法放到构造函数的原型对象上,通过按钮绑定,调用原型对象上的方法,实现对涉及项目的改变 html代码: <!DOCTYPE htm ...

  9. 三.jquery.datatables.js表格编辑与删除

    1.为了使用如图效果(即将按钮放入行内http://www.datatables.net/examples/ajax/null_data_source.html) 采用了另一个数据格式 2.后台php ...

随机推荐

  1. 如何解决ORA-28002 the password will expire within 7 days问题(密码快过期)

    1.问题描述: 今天登陆pl/sql工具时,提示 ORA-28002 the password will expire within 7 days 2.问题原因: oracle11g中默认在defau ...

  2. WebSphere,WebLogic,Tomcat,IIS

    Weblogic.Tomcat 都基于java的基础架构 Weblogic是一个企业级的应用服务器,其中包括j2ee中的各类应用如jsp,servlet,ejb等, Tomcat是一个初级的应用服务器 ...

  3. linux学习--目录切换命令 cd

  4. SpringBoot无法书写主启动类的情况之一

    首先需要引入 spring-boot-starter-web 依赖[springboot web 项目 启动器 jar包]: 如果使用镜像请确保镜像路径正确,可参看笔者博客园m-yb的maven 安装 ...

  5. @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) 注解的作用

    在学习boot 项目的时候 ,发现在启动类中有一个这个的注解 @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) ...

  6. noj装载问题

    描述 有两艘船,载重量分别是c1. c2,n个集装箱,重量是wi (i=1…n),且所有集装箱的总重量不超过c1+c2.确定是否有可能将所有集装箱全部装入两艘船.   输入 多个测例,每个测例的输入占 ...

  7. IO调度算法的理解(转载)

    IO调度器(IO Scheduler)是操作系统用来决定块设备上IO操作提交顺序的方法.存在的目的有两个,一是提高IO吞吐量,二是降低IO响应时间.然而IO吞吐量和IO响应时间往往是矛盾的,为了尽量平 ...

  8. 神州数码广域网PPP封装PAP认证配置

    实验要求:熟练掌握PAP认证配置(单向.双向) 拓扑如下: 单向 R1(验证方) enable 进入特权模式 config 进入全局模式  hostname R1 修改名称 interface s0/ ...

  9. CPU查询

    请问:两路四核超线程=多少CPU??? 答案:16个 一.解释说明 两路=物理主机中,CPU的卡槽,槽位,这个无法增加,一个萝卜一个坑.就更内存卡槽一样,两个内存卡卡槽,a+b=总内存. 路=槽位=插 ...

  10. CCF-URL映射-(正则匹配)-20180303

    果然正则表达式是一个强大的工具 更短的代码....hhh 版本1: 正则表达式..so easy~~ #include <iostream> #include <algorithm& ...