系统定制开发『 高达 购物车案例 』jQuery + Java Script 全功能实现【超详细 代码分析】

🚩 系统定制开发祝大家五一快乐,系统定制开发希望大家在今天代码无 bug!!!

  • 🏆 作者昵称:'' 系统定制开发卡卡西最近怎么样 ''

  • 🏆 作者主页:
  • 🏆 系统定制开发欢迎各位大佬们:点赞👍 收藏💖 关注🤝 留言💬
  • 🏆 系统定制开发如有错误有各位大佬错误请指正!!系统定制开发星光不问赶路人,系统定制开发大家一起进步沉淀!

系统定制开发完整代码压缩包资源:

文章目录:

🔊 

🔊 

🔊 

🔊 


一:前言:

        系统定制开发文章的由来必然是热爱,系统定制开发由于热爱高达模型,系统定制开发也经常逛万代商城了解这些,系统定制开发我相信大部分学软件的系统定制开发我们难免都会有想过写系统定制开发一个自己的网站,系统定制开发此篇文章就是作者对于系统定制开发高达的热爱写的一个功系统定制开发能齐全的高达购物车来系统定制开发作为自己学习某一阶段的检测,使用了 jQuery + Java Script 实现,系统定制开发页面结构条理易读,系统定制开发最主要可以直接拿来 copy,系统定制开发大家一起往下看吧!!


 二:系统定制开发购物车页面及功能实现展示  

 主页面: 

全选勾选页面: 

商品默认均为一件,取消任何一个单选全选会取消,单选全选上全选也会勾选

商品数更改及总价格更改页面: 

如果左侧没有勾选,则单个的价格不会加到下方总价中,物品数量默认为1 ,不会为负数

删除商品页面:

点击右侧删除按钮,可以将此删除对应的物品删除掉 

清空所有宝贝页面: 

清空所有宝贝会有弹窗确认,确认则删除,不确认则返回不删除任何物品

成功清空页面: 

 成功清空会有无宝贝的底层提示,如删除前有总价格与全选,清空后也会取消与清零 

空购物车再清空页面弹窗:

当购物车已经为空时再点击清空按钮,则会弹出以及为空无法清空的弹窗


三:代码分析 

3.1 全选单选切换思路分析

<- 这版块使用 jQuery 实现 ->

思路:

  • 首先注册全选按钮的点击切换 change 事件,通过 jQuery 属性操作 prop 将当前点击的全选按钮的 checked 属性的属性值赋值给每一个单选的按钮的 checked 属性值,使其单选后全部勾选。
  • 单选全选后全选勾选也是一样的原理,如果勾选的单选框的 length 数量等于单选框的数量,则全选按钮勾选,否则不勾选。

⚠ 注意:下方代码是总价格改变的代码,与此功能按钮切换无关

  1. if($(this).prop('checked')==true){ //此代码是总价格改变的判断代码,与此功能无关
  2. allprice() //总价函数
  3. }else if($(this).prop('checked')==false){
  4. allprice() //总价函数
  5. }

全选单选切换代码 : 

  1. $(function(){
  2. $('.qx').change(function(){
  3. // 测试 点击全选输出true/false console.log($(this).prop('checked'));
  4. $('.check').prop('checked',$(this).prop('checked'));
  5. allprice(); //总价函数
  6. })
  7. $('.check').change(function(){
  8. if($(this).prop('checked')==true){ //此代码是总价格改变的判断代码,与此功能无关
  9. allprice() //总价函数
  10. }else if($(this).prop('checked')==false){
  11. allprice() //总价函数
  12. }
  13. else if($('.check:checked').length==$('.check').length){
  14. $('.qx').prop('checked',true);
  15. }else{
  16. $('.qx').prop('checked',false);
  17. }
  18. })

3.2 商品小计加减 及 单总价 思路分析 

<- 这版块使用 jQuery 实现 ->

思路:

  • 分两个版块实现,分别是左侧减数量按钮点击事件和右侧加数量点击事件,该板块主要点在于获取到三个不同层级的内容,这就需要使用文本操作 text() 或者 html(),以及筛选方法,此处主要用到 parent() 找父级与 siblings() 找兄弟级,思路就是点击增减键后先获取到当前的数量值,自增或自减后再赋值给当前数量的文本,就可以达到增减数量小计的操作。
  • 对于单总价的思路就是,小计数量*商品单价,此处我们还用以上筛选方法获取到单价框中的单价值,注意此处获得到的单价值为‘¥xxx’,我们要用字符串操作 substr 截取只得到数值,去掉人民币符号

⚠ 注意:text() 得到的是字符串类型,自增减会自动隐式转换,所以可以自增减,对于单价来说,得到的去掉¥符号的单价也是字符串,相乘时要用 parseInt 转为数字型

拓展:

  •  在此代码中我们使用了两次 parent() 才获取到目标的父级,在实际开发中我们可以采用 parents() 方法,这个方法可以找所有的祖先级,在祖先级中匹配目标父级的类即可快速找到,大大减少代码冗余
  • toFixed ( number ) 可以设置保留几位小数,number为要保留的位数,如果各位的单价为小数可以自行添加此方法,保留两位:toFixed ( 2 ) 

商品小计及单总价变化代码: 

  1. //add 变化,text()获取来的是string类型,自增会隐式转换
  2. $('.number-right').click(function(){
  3. var num=$(this).siblings('.number-center').text();
  4. num++;
  5. $(this).siblings('.number-center').text(num)
  6. //得到点击加号的物品的价格--->'¥xxx'
  7. var a=$(this).parent().parent().siblings('.price').children('div').text();
  8. console.log(a.length);
  9. //去掉¥符号
  10. var single_price=parseInt(a.substr(1,a.length-1))
  11. //赋值
  12. $(this).parent().parent().siblings('.allprice').find('.num').text(single_price*num)
  13. allprice() //总价函数
  14. })
  15. $('.number-left').click(function(){
  16. if($(this).siblings('.number-center').text()=='1'){
  17. $(this).siblings('.number-center').text('1');
  18. $(this).parent().parent().siblings('.allprice').find('.num').text($(this).parent().parent().siblings('.price').children('div').text().substr(1,a.length-1))
  19. }else{
  20. var num=$(this).siblings('.number-center').text();
  21. num--;
  22. $(this).siblings('.number-center').text(num)
  23. //得到点击加号的物品的价格--->'¥xxx',注意此处可以使用parents()来代替parent().parent()
  24. var a=$(this).parent().parent().siblings('.price').children('div').text();
  25. //去掉¥符号
  26. var single_price=parseInt(a.substr(1,a.length-1))
  27. //赋值
  28. $(this).parent().parent().siblings('.allprice').find('.num').text(single_price*num)
  29. allprice() //总价函数
  30. }
  31. })
  32. })

  3.3 总价函数 思路分析

<- 这版块是一个此案例多次调用的总价函数allprice() ->

思路:

最主要的思想:每个物品的单选框有没有选中,只有选上的总单价才会被加到单价中,因此只需要在该函数中判断有没有选中并赋值即可

  • 我们有很多因素都能影响总价格,例如我们已经勾选了某些物品,但是我们再增加数量,价格会变导致总价也会变,但是没有勾选的物品增加数量,总价就不会变,再或者是删掉物品时,勾选的商品被删掉,总价也会被减去,总而言之,就是很多操作都会改变总价格,对此我们很容易想到单独写一个函数将总价获取封装,每次改变总价操作后调用一次即可
  • 函数思路是设置一个总价 sum,由于其最主要的思想就是每个物品的单选框有没有选中,在函数里面判断是否选中,如果选中了,则将该物品总单价赋给其单独的一个 sum1(注意此处并不是总价 sum,案例有四个物品,设置了sum1,sum2,sum3,sum4 进行判断赋值),如果没有选中,则给其该物品的 sum1 赋值为0,四个判断完后我们就可以将其四个值相加,选中的就有其单个物品的总价格,没选中就是 0 去相加,及 sum=sum1+sum2+sum3+sum4

举例一个判断:这个代码是我们第一个物品的判断,根据我们刚才的思想,这个代码意思为:如果第一个物品选中了,则将其总单价赋值给 sum1,没选就赋值0,最后再用 sum1 去相加各个物品的 sum2,sum3 ....... 最后再将总 sum 赋值给总价即可

  1. var price1=parseInt($('.heji1').siblings('.num').text())
  2. if($('.xz-1').children('.check').prop('checked')==true){ //判断第一个全选是否选上
  3. var sum1=price1
  4. }else{
  5. sum1=0
  6. }

 总价函数代码:

  1. function allprice(){
  2. var sum=0;
  3. var price1=parseInt($('.heji1').siblings('.num').text())
  4. var price2=parseInt($('.heji2').siblings('.num').text())
  5. var price3=parseInt($('.heji3').siblings('.num').text())
  6. var price4=parseInt($('.heji4').siblings('.num').text())
  7. if($('.xz-1').children('.check').prop('checked')==true){ //判断第一个全选是否选上
  8. var sum1=price1
  9. }else{
  10. sum1=0
  11. }
  12. if($('.xz-2').children('.check').prop('checked')==true){ //判断第二个全选是否选上
  13. var sum2=price2
  14. }else{
  15. sum2=0
  16. }
  17. if($('.xz-3').children('.check').prop('checked')==true){ //判断第三个全选是否选上
  18. var sum3=price3
  19. }else{
  20. sum3=0
  21. }
  22. if($('.xz-4').children('.check').prop('checked')==true){ //判断第四个全选是否选上
  23. var sum4=price4
  24. }else{
  25. sum4=0
  26. }
  27. sum=sum1+sum2+sum3+sum4
  28. console.log(sum);
  29. $('.price-a').text(sum);
  30. }

3.4 删除单个物品思路分析  

<- 这版块使用 原生 Java Script 实现 ->

思路:

  • 用到了节点操作之删除节点:removechild(),此版块不难很容易实现,for 循环遍历每一个 del 删除按钮,给每个按钮绑定一个删除节点的操作即可,此处删除的是父节点的父节点:this.parentNode.parentNode

⚠ 注意:删除后要调用 总价函数 allprice() 判断更改总价值

 删除单个物品代码:

  1. for(var i=0;i<delbtn.length;i++){
  2. delbtn[i].addEventListener('click',function(){
  3. // 测试用的
  4. // console.log(objects.length);
  5. // console.log(main.children.length);
  6. main.removeChild(this.parentNode.parentNode)
  7. allprice()
  8. if(main.children.length==0){
  9. nullbgimg.style.display='block'
  10. nullbgtext.style.display='block'
  11. qx.checked=false;
  12. }
  13. })
  14. }

3.5 删除全部物品思路分析

<- 这版块使用 原生 Java Script 实现 ->

思路:

  • 此版块也无难点,唯一需要注意的地方就是:我在这里用的是,点击全删按钮并判断确认后使用循环遍历每一件商品,每遍历一次就删除第一件商品,直到删完,这就需要我们保证遍历过程中的数量是不变的(意思就是我们 for 循环中小于的那个值),此处如果使用 i<main.children.length,则我们需要点两次删除才能删完,这是因为删除过程中其 main.children 的数量是在不断减少的,因此需要点两次,如何解决?
  • 要解决这个问题,我们就要选择一个不变的值,此处我选择了 objects.lengthobjects 是获取来的 DOM 对象,开始获取到几个它的值就是几个,及时物品被删除其值也不会变

⚠ 注意:此处我选择的方法较为笨,还有很多容易的方法可以实现,包括更容易的 jQuery,大家自行看着更改更聪明的方法

删除全部物品代码:

  1. clearbtn.addEventListener('click',function(){
  2. if(main.children.length==0){
  3. nullalert.style.display='block';
  4. mask.style.display='block'
  5. nullbtn.addEventListener('click',function(){
  6. nullalert.style.display='none';
  7. mask.style.display='none'
  8. nullbgimg.style.display='block'
  9. nullbgtext.style.display='block'
  10. })
  11. }else{
  12. alert.style.display='block';
  13. mask.style.display='block'
  14. yes.addEventListener('click',function(){
  15. alert.style.display='none';
  16. mask.style.display='none';
  17. for(var i=0;i<objects.length;i++){
  18. main.removeChild(main.children[0])
  19. }
  20. allprice()
  21. qx.checked=false
  22. nullbgimg.style.display='block'
  23. nullbgtext.style.display='block'
  24. })
  25. no.addEventListener('click',function(){
  26. alert.style.display='none';
  27. mask.style.display='none';
  28. })
  29. }
  30. })

 四:完整代码

      完整代码两部分,注意分两个文件,还有jQuery文件需自行引入,再有就是注意引入文件的路径自行更改

4.1 HTML+CSS 文件 : 

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>我的购物车</title>
  8. <style>
  9. *{
  10. margin: 0;
  11. padding: 0;
  12. }
  13. body{
  14. background-color: rgb(255, 240, 222);
  15. }
  16. .mask{
  17. display: none;
  18. position: absolute;
  19. z-index: 10;
  20. width: 1440px;
  21. height: 845px;
  22. background-color: rgba(0, 0, 0, 0.517);
  23. }
  24. .left{
  25. /* display: none; */
  26. position: relative;
  27. box-sizing: border-box;
  28. width: 100px;
  29. height: 843px;
  30. margin: 10px;
  31. margin-top: 0;
  32. float: left;
  33. /* background-color: rgb(255, 164, 59); */
  34. background-color: rgb(255, 197, 111);
  35. border: 1.3px solid black;
  36. border-top: 15px solid rgb(150, 150, 150);
  37. }
  38. .right{
  39. position: relative;
  40. /* display: none; */
  41. float: left;
  42. box-sizing: border-box;
  43. width: 1300px;
  44. height: 843px;
  45. }
  46. .left .left-img{
  47. position: absolute;
  48. top: 19px;
  49. left: 19px;
  50. width: 65px;
  51. height: 65px;
  52. }
  53. .left ul{
  54. box-sizing: border-box;
  55. position: absolute;
  56. top: 130px;
  57. border-top: 3px solid #fff;
  58. width: 98px;
  59. }
  60. .left ul li{
  61. box-sizing: border-box;
  62. list-style: none;
  63. width: 98px;
  64. height: 130px;
  65. border-bottom: 3px solid rgb(255, 255, 255);
  66. /* background-color: rgb(255, 186, 108); */
  67. background-color: rgb(255, 200, 119);
  68. color: rgb(255, 255, 255);
  69. font-size: 22px;
  70. font-weight: bold;
  71. text-shadow: 2px 2px 2px rgb(77, 77, 77);
  72. text-align: center;
  73. padding-left: 18px;
  74. padding-right: 18px;
  75. padding-top: 22px;
  76. line-height: 40px;
  77. cursor: pointer;
  78. }
  79. .left ul li:hover{
  80. background-color: rgb(255, 219, 172);
  81. }
  82. .banner{
  83. position: relative;
  84. box-sizing: border-box;
  85. width: 1300px;
  86. height: 130px;
  87. /* background-color: rgb(255, 164, 59); */
  88. background-color: rgb(255, 200, 116);
  89. margin: 0 auto;
  90. margin-bottom: 9px;
  91. border: 1.3px solid black;
  92. border-top: 15px solid rgb(150, 150, 150);
  93. }
  94. .banner img{
  95. position: absolute;
  96. top: 22px;
  97. left: 50px;
  98. float: left;
  99. width: 60px;
  100. height: 60px;
  101. }
  102. .banner p{
  103. position: absolute;
  104. left: 130px;
  105. top: 35px;
  106. float: left;
  107. font-size: 27px;
  108. font-weight: bold;
  109. text-shadow: 2px 2px 2px grey;
  110. color: #fff;
  111. }
  112. .search-box{
  113. position: relative;
  114. width: 700px;
  115. height: 114px;
  116. box-sizing: border-box;
  117. float: right;
  118. /* background-color: rgb(255, 188, 188); */
  119. }
  120. .search{
  121. box-sizing: border-box;
  122. float: left;
  123. position: absolute;
  124. top: 35px;
  125. left: 180px;
  126. width: 370px;
  127. height: 50px;
  128. padding-left: 20px;
  129. -webkit-border-radius:40px;
  130. -moz-border-radius:40px;
  131. font-size: 20px;
  132. font-weight: bold;
  133. color: rgb(71, 71, 71);
  134. border: 1.3px solid rgb(78, 78, 78);
  135. outline: none;
  136. }
  137. .banner .search-img{
  138. position: absolute;
  139. float: left;
  140. top: 33px;
  141. left: 562px;
  142. width: 50px;
  143. height: 50px;
  144. }
  145. ::placeholder{
  146. color: rgb(181, 181, 181);
  147. }
  148. .object{
  149. /* display: none; */
  150. box-sizing: border-box;
  151. width: 1300px;
  152. height: 220px;
  153. margin: 0 auto ;
  154. margin-bottom: 15px;
  155. border: 1.3px solid rgb(90, 90, 90);
  156. background-color: rgb(243, 243, 243);
  157. border-top: 6px solid rgb(194, 194, 194);
  158. }
  159. .main{
  160. width: 1300px;
  161. height: 615px;
  162. box-sizing: border-box;
  163. overflow-y: scroll;
  164. }
  165. .buybox{
  166. box-sizing: border-box;
  167. width: 1300px;
  168. height: 90px;
  169. margin: 0 auto ;
  170. margin-bottom: 20px;
  171. border: 1.3px solid rgb(90, 90, 90);
  172. background-color: rgb(255, 226, 183);
  173. }
  174. .xz-1{
  175. box-sizing: border-box;
  176. position: relative;
  177. float: left;
  178. width: 100px;
  179. height: 212.7px;
  180. }
  181. .xz-2{
  182. box-sizing: border-box;
  183. position: relative;
  184. float: left;
  185. width: 100px;
  186. height: 212.7px;
  187. }
  188. .xz-3{
  189. box-sizing: border-box;
  190. position: relative;
  191. float: left;
  192. width: 100px;
  193. height: 212.7px;
  194. }
  195. .xz-4{
  196. box-sizing: border-box;
  197. position: relative;
  198. float: left;
  199. width: 100px;
  200. height: 212.7px;
  201. }
  202. .img-1{
  203. box-sizing: border-box;
  204. position: relative;
  205. float: left;
  206. width: 190px;
  207. height: 212.7px;
  208. }
  209. .img-2{
  210. box-sizing: border-box;
  211. position: relative;
  212. float: left;
  213. width: 190px;
  214. height: 212.7px;
  215. }
  216. .img-3{
  217. box-sizing: border-box;
  218. position: relative;
  219. float: left;
  220. width: 190px;
  221. height: 212.7px;
  222. }
  223. .img-4{
  224. box-sizing: border-box;
  225. position: relative;
  226. float: left;
  227. width: 190px;
  228. height: 212.7px;
  229. }
  230. .information-1{
  231. box-sizing: border-box;
  232. float: left;
  233. width: 280px;
  234. height: 212.7px;
  235. /* background-color: rgb(255, 219, 219); */
  236. margin-right: 100px;
  237. padding-left: 20px;
  238. padding-top: 30px;
  239. padding-right: 5px;
  240. font-size: 17px;
  241. font-weight: bold;
  242. color: rgb(68, 68, 68);
  243. text-shadow: 2px 2px 2px #fff;
  244. }
  245. .information-2{
  246. box-sizing: border-box;
  247. float: left;
  248. width: 280px;
  249. height: 212.7px;
  250. /* background-color: rgb(255, 219, 219); */
  251. margin-right: 100px;
  252. padding-left: 20px;
  253. padding-right: 5px;
  254. padding-top: 30px;
  255. font-size: 17px;
  256. font-weight: bold;
  257. color: rgb(68, 68, 68);
  258. text-shadow: 2px 2px 2px #fff;
  259. }
  260. .information-3{
  261. box-sizing: border-box;
  262. float: left;
  263. width: 280px;
  264. height: 212.7px;
  265. /* background-color: rgb(255, 219, 219); */
  266. margin-right: 100px;
  267. padding-left: 20px;
  268. padding-right: 5px;
  269. padding-top: 30px;
  270. font-size: 17px;
  271. font-weight: bold;
  272. color: rgb(68, 68, 68);
  273. text-shadow: 2px 2px 2px #fff;
  274. }
  275. .information-4{
  276. box-sizing: border-box;
  277. float: left;
  278. width: 280px;
  279. height: 212.7px;
  280. /* background-color: rgb(255, 219, 219); */
  281. margin-right: 100px;
  282. padding-left: 20px;
  283. padding-right: 5px;
  284. padding-top: 30px;
  285. font-size: 17px;
  286. font-weight: bold;
  287. color: rgb(68, 68, 68);
  288. text-shadow: 2px 2px 2px #fff;
  289. }
  290. .price{
  291. position: relative;
  292. left: -55px;
  293. box-sizing: border-box;
  294. float: left;
  295. width: 140px;
  296. height: 212.7px;
  297. /* background-color: rgb(212, 196, 196); */
  298. padding-top: 26px;
  299. font-size: 28px;
  300. font-weight: bold;
  301. color: rgb(255, 5, 5);
  302. }
  303. .price span{
  304. text-decoration: line-through;
  305. font-size: 18px;
  306. color: rgb(58, 58, 58);
  307. }
  308. .number-1{
  309. box-sizing: border-box;
  310. position: relative;
  311. float: left;
  312. width: 200px;
  313. height: 212.7px;
  314. left: -20px;
  315. /* background-color: rgb(255, 219, 219); */
  316. }
  317. .number-2{
  318. box-sizing: border-box;
  319. position: relative;
  320. float: left;
  321. width: 200px;
  322. height: 212.7px;
  323. left: -20px;
  324. /* background-color: rgb(255, 219, 219); */
  325. }
  326. .number-3{
  327. box-sizing: border-box;
  328. position: relative;
  329. float: left;
  330. width: 200px;
  331. height: 212.7px;
  332. left: -20px;
  333. /* background-color: rgb(255, 219, 219); */
  334. }
  335. .number-4{
  336. box-sizing: border-box;
  337. position: relative;
  338. float: left;
  339. width: 200px;
  340. height: 212.7px;
  341. left: -20px;
  342. /* background-color: rgb(255, 219, 219); */
  343. }
  344. .allprice{
  345. box-sizing: border-box;
  346. position: relative;
  347. float: left;
  348. width: 180px;
  349. height: 212.7px;
  350. left: -20px;
  351. /* background-color: rgb(212, 196, 196); */
  352. }
  353. .del-1{
  354. box-sizing: border-box;
  355. position: relative;
  356. float: left;
  357. width: 107.40px;
  358. height: 212.7px;
  359. left: -15px;
  360. /* background-color: rgb(255, 219, 219); */
  361. }
  362. .del-2{
  363. box-sizing: border-box;
  364. position: relative;
  365. float: left;
  366. width: 107.40px;
  367. height: 212.7px;
  368. left: -15px;
  369. /* background-color: rgb(255, 219, 219); */
  370. }
  371. .del-3{
  372. box-sizing: border-box;
  373. position: relative;
  374. float: left;
  375. width: 107.40px;
  376. height: 212.7px;
  377. left: -15px;
  378. /* background-color: rgb(255, 219, 219); */
  379. }
  380. .del-4{
  381. box-sizing: border-box;
  382. position: relative;
  383. float: left;
  384. width: 107.40px;
  385. height: 212.7px;
  386. left: -15px;
  387. /* background-color: rgb(255, 219, 219); */
  388. }
  389. .check{
  390. position: absolute;
  391. left: 37px;
  392. top: 30px;
  393. box-sizing: border-box;
  394. width: 25px;
  395. height: 25px;
  396. cursor: pointer;
  397. /* -webkit-border-radius:10px;
  398. -moz-border-radius:10px; */
  399. }
  400. .gaodaimg-1{
  401. position: absolute;
  402. top: 15px;
  403. left: 3px;
  404. width: 180px;
  405. height: 180px;
  406. border: 1px solid rgb(91, 91, 91);
  407. cursor: pointer;
  408. }
  409. .gaodaimg-2{
  410. position: absolute;
  411. top: 15px;
  412. left: 3px;
  413. width: 180px;
  414. height: 180px;
  415. border: 1px solid rgb(91, 91, 91);
  416. cursor: pointer;
  417. }
  418. .gaodaimg-3{
  419. position: absolute;
  420. top: 15px;
  421. left: 3px;
  422. width: 180px;
  423. height: 180px;
  424. border: 1px solid rgb(91, 91, 91);
  425. cursor: pointer;
  426. }
  427. .gaodaimg-4{
  428. position: absolute;
  429. top: 15px;
  430. left: 3px;
  431. width: 180px;
  432. height: 180px;
  433. border: 1px solid rgb(91, 91, 91);
  434. cursor: pointer;
  435. }
  436. .manjian-1{
  437. float: left;
  438. margin-top: 8px;
  439. margin-left: 10px;
  440. width: 80px;
  441. height: 25px;
  442. background-color: rgb(227, 0, 0);
  443. color: #fff;
  444. font-size: 7px;
  445. font-weight: bold;
  446. text-shadow: none;
  447. text-align: center;
  448. line-height: 25px;
  449. -webkit-border-radius:10px;
  450. -moz-border-radius:10px;
  451. margin-right: 10px;
  452. }
  453. .manjian-2{
  454. float: left;
  455. margin-top: 8px;
  456. margin-left: 10px;
  457. width: 80px;
  458. height: 25px;
  459. background-color: rgb(227, 0, 0);
  460. color: #fff;
  461. font-size: 7px;
  462. font-weight: bold;
  463. text-shadow: none;
  464. text-align: center;
  465. line-height: 25px;
  466. -webkit-border-radius:10px;
  467. -moz-border-radius:10px;
  468. margin-right: 10px;
  469. }
  470. .manjian-3{
  471. float: left;
  472. margin-top: 8px;
  473. margin-left: 10px;
  474. width: 80px;
  475. height: 25px;
  476. background-color: rgb(227, 0, 0);
  477. color: #fff;
  478. font-size: 7px;
  479. font-weight: bold;
  480. text-shadow: none;
  481. text-align: center;
  482. line-height: 25px;
  483. -webkit-border-radius:10px;
  484. -moz-border-radius:10px;
  485. margin-right: 10px;
  486. }
  487. .manjian-4{
  488. float: left;
  489. margin-top: 8px;
  490. margin-left: 10px;
  491. width: 80px;
  492. height: 25px;
  493. background-color: rgb(227, 0, 0);
  494. color: #fff;
  495. font-size: 7px;
  496. font-weight: bold;
  497. text-shadow: none;
  498. text-align: center;
  499. line-height: 25px;
  500. -webkit-border-radius:10px;
  501. -moz-border-radius:10px;
  502. margin-right: 10px;
  503. }
  504. .brand{
  505. float: left;
  506. margin-top: 8px;
  507. width: 80px;
  508. height: 25px;
  509. background-color: rgb(0, 0, 0);
  510. color: rgb(255, 249, 208);
  511. font-size: 7px;
  512. font-weight: bold;
  513. text-shadow: none;
  514. text-align: center;
  515. line-height: 25px;
  516. -webkit-border-radius:10px;
  517. -moz-border-radius:10px;
  518. margin-right: 15px;
  519. }
  520. /* 按钮 */
  521. .number-box{
  522. box-sizing: border-box;
  523. position: absolute;
  524. top: 45px;
  525. left: -27px;
  526. width: 175px;
  527. height: 50px;
  528. border: 1px solid black;
  529. }
  530. .number-box .number-left{
  531. float: left;
  532. box-sizing: border-box;
  533. width: 54px;
  534. height: 48px;
  535. border-right: 1px solid black;
  536. background-color: #fff;
  537. text-align: center;
  538. line-height: 50px;
  539. font-size: 30px;
  540. font-weight: bold;
  541. cursor: pointer;
  542. }
  543. .number-box .number-left:hover{
  544. background-color: rgb(220, 220, 220);
  545. }
  546. .number-box .number-center{
  547. float: left;
  548. box-sizing: border-box;
  549. width: 64px;
  550. height: 48px;
  551. background-color: #fff;
  552. text-align: center;
  553. line-height: 50px;
  554. font-size: 25px;
  555. font-weight: bold;
  556. }
  557. .number-box .number-right{
  558. float: left;
  559. box-sizing: border-box;
  560. width: 54px;
  561. height: 48px;
  562. border-left: 1px solid black;
  563. background-color: #fff;
  564. text-align: center;
  565. line-height: 50px;
  566. font-size: 30px;
  567. font-weight: bold;
  568. cursor: pointer;
  569. }
  570. .number-box .number-right:hover{
  571. background-color: rgb(220, 220, 220);
  572. }
  573. /* 一的合计 */
  574. .allprice-box{
  575. position: absolute;
  576. top: 50px;
  577. left: -8px;
  578. width: 164px;
  579. height: 60px;
  580. }
  581. .allprice .heji1{
  582. float: left;
  583. width: 50px;
  584. height: 40px;
  585. font-size: 18px;
  586. font-weight: bold;
  587. line-height: 40px;
  588. }
  589. .allprice .biaozhi1{
  590. float: left;
  591. width: 25px;
  592. height: 60px;
  593. /* background-color: rgb(255, 106, 106); */
  594. font-size: 28px;
  595. font-weight: bold;
  596. color: rgb(234, 0, 0);
  597. }
  598. .allprice .num{
  599. float: left;
  600. width: 89px;
  601. height: 60px;
  602. /* background-color: rgb(255, 173, 173); */
  603. font-size: 28px;
  604. font-weight: bold;
  605. color: rgb(234, 0, 0);
  606. }
  607. /* 二的合计 */
  608. .allprice-box{
  609. position: absolute;
  610. top: 50px;
  611. left: -8px;
  612. width: 164px;
  613. height: 60px;
  614. }
  615. .allprice .heji2{
  616. float: left;
  617. width: 50px;
  618. height: 40px;
  619. font-size: 18px;
  620. font-weight: bold;
  621. line-height: 40px;
  622. }
  623. .allprice .biaozhi2{
  624. float: left;
  625. width: 25px;
  626. height: 60px;
  627. /* background-color: rgb(255, 106, 106); */
  628. font-size: 28px;
  629. font-weight: bold;
  630. color: rgb(234, 0, 0);
  631. }
  632. .allprice .num{
  633. float: left;
  634. width: 89px;
  635. height: 60px;
  636. /* background-color: rgb(255, 173, 173); */
  637. font-size: 28px;
  638. font-weight: bold;
  639. color: rgb(234, 0, 0);
  640. }
  641. /* 三的合计 */
  642. .allprice-box{
  643. position: absolute;
  644. top: 50px;
  645. left: -8px;
  646. width: 164px;
  647. height: 60px;
  648. }
  649. .allprice .heji3{
  650. float: left;
  651. width: 50px;
  652. height: 40px;
  653. font-size: 18px;
  654. font-weight: bold;
  655. line-height: 40px;
  656. }
  657. .allprice .biaozhi3{
  658. float: left;
  659. width: 25px;
  660. height: 60px;
  661. /* background-color: rgb(255, 106, 106); */
  662. font-size: 28px;
  663. font-weight: bold;
  664. color: rgb(234, 0, 0);
  665. }
  666. .allprice .num{
  667. float: left;
  668. width: 89px;
  669. height: 60px;
  670. /* background-color: rgb(255, 173, 173); */
  671. font-size: 28px;
  672. font-weight: bold;
  673. color: rgb(234, 0, 0);
  674. }
  675. /* 四的合计 */
  676. .allprice-box{
  677. position: absolute;
  678. top: 50px;
  679. left: -8px;
  680. width: 164px;
  681. height: 60px;
  682. }
  683. .allprice .heji4{
  684. float: left;
  685. width: 50px;
  686. height: 40px;
  687. font-size: 18px;
  688. font-weight: bold;
  689. line-height: 40px;
  690. }
  691. .allprice .biaozhi4{
  692. float: left;
  693. width: 25px;
  694. height: 60px;
  695. /* background-color: rgb(255, 106, 106); */
  696. font-size: 28px;
  697. font-weight: bold;
  698. color: rgb(234, 0, 0);
  699. }
  700. .allprice .num{
  701. float: left;
  702. width: 89px;
  703. height: 60px;
  704. /* background-color: rgb(255, 173, 173); */
  705. font-size: 28px;
  706. font-weight: bold;
  707. color: rgb(234, 0, 0);
  708. }
  709. /* 删除按钮 */
  710. .delbtn{
  711. position: absolute;
  712. top: 50px;
  713. left: -15px;
  714. width: 90px;
  715. height: 40px;
  716. background-color: rgb(255, 164, 59);
  717. border: 1px solid grey;
  718. -webkit-border-radius:10px;
  719. -moz-border-radius:10px;
  720. font-size: 15px;
  721. font-weight: bold;
  722. color: #fff;
  723. text-shadow: 2px 2px 2px rgb(80, 80, 80);
  724. cursor: pointer;
  725. }
  726. .delbtn:hover{
  727. background-color: rgb(255, 206, 137);
  728. color: rgb(90, 90, 90);
  729. text-shadow: none;
  730. }
  731. .qxbox{
  732. position: relative;
  733. box-sizing: border-box;
  734. float: left;
  735. width: 240px;
  736. height: 90px;
  737. /* background-color: rgb(255, 194, 194); */
  738. }
  739. .qx{
  740. box-sizing: border-box;
  741. position: absolute;
  742. top: 35px;
  743. left: 40px;
  744. width: 25px;
  745. height: 25px;
  746. cursor: pointer;
  747. }
  748. .myt{
  749. box-sizing: border-box;
  750. position: absolute;
  751. top: 35px;
  752. left: 75px;
  753. width: 150px;
  754. height: 25px;
  755. font-size: 18px;
  756. font-weight: bold;
  757. color: rgb(87, 87, 87);
  758. }
  759. .clear{
  760. box-sizing: border-box;
  761. position: relative;
  762. float: left;
  763. width: 320px;
  764. height: 90px;
  765. /* background-color: rgb(255, 86, 86); */
  766. margin-right: 50px;
  767. }
  768. .price-box{
  769. position: relative;
  770. box-sizing: border-box;
  771. float: left;
  772. width: 370px;
  773. height: 90px;
  774. /* background-color: rgb(255, 86, 86); */
  775. }
  776. .jiesuan-box{
  777. box-sizing: border-box;
  778. position: relative;
  779. float: left;
  780. width: 300px;
  781. height: 90px;
  782. /* background-color: rgb(255, 184, 184); */
  783. }
  784. .btn-clear{
  785. position: absolute;
  786. top: 16px;
  787. width: 250px;
  788. height: 60px;
  789. -webkit-border-radius:10px;
  790. -moz-border-radius:10px;
  791. font-size: 20px;
  792. font-weight: bold;
  793. color: rgb(63, 63, 63);
  794. border: 1.3px solid rgb(42, 42, 42);
  795. background-color: rgb(243, 243, 243);
  796. cursor: pointer;
  797. }
  798. .btn-clear:hover{
  799. background-color: rgb(182, 182, 182);
  800. color: #fff;
  801. text-shadow: 2px 2px 2px rgb(108, 108, 108);
  802. }
  803. .price-box p{
  804. position: absolute;
  805. top: 27px;
  806. left: 20px;
  807. font-size: 25px;
  808. font-weight: bold;
  809. }
  810. .price-box .price-a{
  811. position: absolute;
  812. top: 19px;
  813. left: 130px;
  814. font-size: 35px;
  815. color: rgb(206, 31, 31);
  816. font-weight: bold;
  817. }
  818. .jiesuan{
  819. box-sizing: border-box;
  820. position: absolute;
  821. top: 10px;
  822. left: 10px;
  823. width: 200px;
  824. height: 70px;
  825. background-color: rgb(204, 0, 0);
  826. color: #fff;
  827. font-size: 30px;
  828. font-weight: bold;
  829. -webkit-border-radius:10px;
  830. -moz-border-radius:10px;
  831. cursor: pointer;
  832. }
  833. .jiesuan:hover{
  834. background-color: rgb(255, 82, 82);
  835. color: rgb(63, 63, 63);
  836. }
  837. /* 购物车弹窗 */
  838. .alert-window{
  839. display: none;
  840. z-index: 11;
  841. box-sizing: border-box;
  842. position: fixed;
  843. top: 200px;
  844. left: 470px;
  845. width: 500px;
  846. height: 350px;
  847. border: 1.4px solid black;
  848. border-top: 40px solid rgb(70, 172, 255);
  849. background-color: rgb(255, 255, 255);
  850. }
  851. .alert-img{
  852. margin-top: 30px;
  853. margin-left: 200px;
  854. width: 90px;
  855. height: 90px;
  856. }
  857. .alert-text{
  858. position: absolute;
  859. box-sizing: border-box;
  860. text-align: center;
  861. line-height: 80px;
  862. width: 497.2px;
  863. height: 100px;
  864. /* background-color: rgb(255, 128, 128); */
  865. font-size: 23px;
  866. font-weight: bold;
  867. color: rgb(53, 53, 53);
  868. }
  869. .no{
  870. position: absolute;
  871. left: 60px;
  872. bottom: 40px;
  873. width: 130px;
  874. height: 60px;
  875. -webkit-border-radius:10px;
  876. -moz-border-radius:10px;
  877. border: 1.3px solid black;
  878. color: rgb(255, 255, 255);
  879. font-size: 23px;
  880. font-weight: bold;
  881. background-color: rgb(225, 0, 0);
  882. }
  883. .no:hover{
  884. color: rgb(81, 81, 81);
  885. background-color: rgb(255, 149, 149);
  886. }
  887. .yes{
  888. position: absolute;
  889. right: 60px;
  890. bottom: 40px;
  891. width: 130px;
  892. height: 60px;
  893. -webkit-border-radius:10px;
  894. -moz-border-radius:10px;
  895. border: 1.3px solid black;
  896. color: rgb(255, 255, 255);
  897. font-size: 23px;
  898. font-weight: bold;
  899. background-color: rgb(34, 185, 0);
  900. }
  901. .yes:hover{
  902. color: rgb(81, 81, 81);
  903. background-color: rgb(152, 255, 150);
  904. }
  905. /* 空购物车弹窗 */
  906. .null-alert-window{
  907. display: none;
  908. z-index: 11;
  909. box-sizing: border-box;
  910. position: fixed;
  911. top: 200px;
  912. left: 470px;
  913. width: 500px;
  914. height: 350px;
  915. border: 1.4px solid black;
  916. border-top: 40px solid rgb(70, 172, 255);
  917. background-color: rgb(255, 255, 255);
  918. }
  919. .null-alert-img{
  920. margin-top: 30px;
  921. margin-left: 200px;
  922. width: 90px;
  923. height: 90px;
  924. }
  925. .null-alert-text{
  926. position: absolute;
  927. box-sizing: border-box;
  928. text-align: center;
  929. line-height: 80px;
  930. width: 497.2px;
  931. height: 100px;
  932. /* background-color: rgb(255, 128, 128); */
  933. font-size: 23px;
  934. font-weight: bold;
  935. color: rgb(53, 53, 53);
  936. }
  937. .null-re{
  938. position: absolute;
  939. left: 96px;
  940. bottom: 40px;
  941. width: 300px;
  942. height: 70px;
  943. -webkit-border-radius:20px;
  944. -moz-border-radius:20px;
  945. border: 1.3px solid black;
  946. color: rgb(255, 255, 255);
  947. font-size: 26px;
  948. font-weight: bold;
  949. background-color: rgb(255, 140, 0);
  950. }
  951. .null-re:hover{
  952. color: rgb(60, 60, 60);
  953. background-color: rgb(255, 172, 100);
  954. }
  955. /* 空购物车背景 */
  956. .nullbg-img{
  957. display: none;
  958. position: absolute;
  959. top: 250px;
  960. left: 620px;
  961. box-sizing: border-box;
  962. width: 250px;
  963. height: 250px;
  964. }
  965. .nullbg-text{
  966. display: none;
  967. position: absolute;
  968. top: 495px;
  969. left: 580px;
  970. box-sizing: border-box;
  971. font-size: 40px;
  972. font-weight: bold;
  973. color: rgb(255, 144, 24);
  974. }
  975. </style>
  976. <script src="./jquery.js"></script>
  977. <script src="./main.js"></script>
  978. </head>
  979. <body>
  980. <div class="left">
  981. <img src="./photo/个性.png" alt="" class="left-img">
  982. <ul>
  983. <li>回到首页</li>
  984. <li>我的收藏</li>
  985. <li>历史记录</li>
  986. <li>退出登录</li>
  987. </ul>
  988. </div>
  989. <div class="right">
  990. <div class="banner">
  991. <img src="./photo/购物车.png" alt="">
  992. <p>您的购物车</p>
  993. <div class="search-box">
  994. <input type="text" class="search" placeholder="请输入您要查找的商品">
  995. <img src="./photo/搜索.png" alt="" class="search-img">
  996. </div>
  997. </div>
  998. <div class="main">
  999. <div class="object">
  1000. <div class="xz-1">
  1001. <input type="checkbox" class="check">
  1002. </div>
  1003. <div class="img-1">
  1004. <img src="./photo/gaoda1.jpg" alt="GP-01 玉兰高达" title="GP-01 玉兰高达" class="gaodaimg-1">
  1005. </div>
  1006. <div class="information-1">【万代】高达拼装 MG 1/100 GP-01 玉兰高达 拼装模型<br>
  1007. <div class="manjian-1">1000减200</div>
  1008. <div class="brand">品&nbsp;&nbsp;牌</div>
  1009. </div>
  1010. <div class="price">
  1011. <span>
  1012. ¥243
  1013. </span><br>
  1014. <div>¥202</div>
  1015. </div>
  1016. <div class="number-1">
  1017. <div class="number-box">
  1018. <div class='number-left'>-</div>
  1019. <div class="number-center">1</div>
  1020. <div class="number-right">+</div>
  1021. </div>
  1022. </div>
  1023. <div class="allprice">
  1024. <div class="allprice-box">
  1025. <div class="heji1">合计:</div>
  1026. <div class="biaozhi1">¥</div>
  1027. <div class="num">202</div>
  1028. </div>
  1029. </div>
  1030. <div class="del-1">
  1031. <button class="delbtn">删除物品</button>
  1032. </div>
  1033. </div>
  1034. <div class="object">
  1035. <div class="xz-2">
  1036. <input type="checkbox" class="check">
  1037. </div>
  1038. <div class="img-2">
  1039. <img src="./photo/gaoda2.jpg" alt="VER-KA 海牛高达" title="VER-KA 海牛高达" class="gaodaimg-2">
  1040. </div>
  1041. <div class="information-2">【万代】高达拼装 MG 1/100 VER-KA 海牛高达 拼装模型<br>
  1042. <div class="manjian-2">1000减200</div>
  1043. <div class="brand">品&nbsp;&nbsp;牌</div>
  1044. </div>
  1045. <div class="price">
  1046. <span>
  1047. ¥575
  1048. </span><br>
  1049. <div>¥545</div>
  1050. </div>
  1051. <div class="number-2">
  1052. <div class="number-box">
  1053. <div class='number-left'>-</div>
  1054. <div class="number-center">1</div>
  1055. <div class="number-right">+</div>
  1056. </div>
  1057. </div>
  1058. <div class="allprice">
  1059. <div class="allprice-box">
  1060. <div class="heji2">合计:</div>
  1061. <div class="biaozhi2">¥</div>
  1062. <div class="num">545</div>
  1063. </div>
  1064. </div>
  1065. <div class="del-2">
  1066. <button class="delbtn">删除物品</button>
  1067. </div>
  1068. </div>
  1069. <div class="object">
  1070. <div class="xz-3">
  1071. <input type="checkbox" class="check">
  1072. </div>
  1073. <div class="img-3">
  1074. <img src="./photo/gaoda3.jpg" alt="EW-WING 飞翼高达" title="EW-WING 飞翼高达" class="gaodaimg-3">
  1075. </div>
  1076. <div class="information-3">【万代】高达拼装 MG 1/100 EW-WING 飞翼高达 拼装模型<br>
  1077. <div class="manjian-3">1000减200</div>
  1078. <div class="brand">品&nbsp;&nbsp;牌</div>
  1079. </div>
  1080. <div class="price">
  1081. <span>
  1082. ¥305
  1083. </span><br>
  1084. <div>¥275</div>
  1085. </div>
  1086. <div class="number-3">
  1087. <div class="number-box">
  1088. <div class='number-left'>-</div>
  1089. <div class="number-center">1</div>
  1090. <div class="number-right">+</div>
  1091. </div>
  1092. </div>
  1093. <div class="allprice">
  1094. <div class="allprice-box">
  1095. <div class="heji3">合计:</div>
  1096. <div class="biaozhi3">¥</div>
  1097. <div class="num">275</div>
  1098. </div>
  1099. </div>
  1100. <div class="del-3">
  1101. <button class="delbtn">删除物品</button>
  1102. </div>
  1103. </div>
  1104. <div class="object">
  1105. <div class="xz-4">
  1106. <input type="checkbox" class="check">
  1107. </div>
  1108. <div class="img-4">
  1109. <img src="./photo/gaoda4.jpg" alt="VER-KA 海牛高达" title="VER-KA 海牛高达" class="gaodaimg-4">
  1110. </div>
  1111. <div class="information-4">【万代】高达拼装 MG 1/100 STRIKE 自由高达 拼装模型<br>
  1112. <div class="manjian-4">1000减200</div>
  1113. <div class="brand">品&nbsp;&nbsp;牌</div>
  1114. </div>
  1115. <div class="price">
  1116. <span>
  1117. ¥399
  1118. </span><br>
  1119. <div>¥309</div>
  1120. </div>
  1121. <div class="number-4">
  1122. <div class="number-box">
  1123. <div class='number-left'>-</div>
  1124. <div class="number-center">1</div>
  1125. <div class="number-right">+</div>
  1126. </div>
  1127. </div>
  1128. <div class="allprice">
  1129. <div class="allprice-box">
  1130. <div class="heji4">合计:</div>
  1131. <div class="biaozhi4">¥</div>
  1132. <div class="num">309</div>
  1133. </div>
  1134. </div>
  1135. <div class="del-4">
  1136. <button class="delbtn">删除物品</button>
  1137. </div>
  1138. </div>
  1139. </div>
  1140. <!-- buy -->
  1141. <div class="buybox">
  1142. <div class="qxbox">
  1143. <input type="checkbox" class="qx">
  1144. <div class="myt">选中全部宝贝</div>
  1145. </div>
  1146. <div class="clear">
  1147. <button class="btn-clear">清空所有宝贝</button>
  1148. </div>
  1149. <div class="price-box">
  1150. <p>共合计:¥</p>
  1151. <div class="price-a">0</div>
  1152. </div>
  1153. <div class="jiesuan-box">
  1154. <button class="jiesuan">结&nbsp;&nbsp;算</button>
  1155. </div>
  1156. </div>
  1157. </div>
  1158. <!-- 遮盖层 -->
  1159. <div class='mask'></div>
  1160. <!-- 全删弹窗 -->
  1161. <div class="alert-window">
  1162. <img src="./photo/等待确认 (1).png" alt="" class="alert-img">
  1163. <div class="alert-text">您确认删除所有宝贝吗?</div>
  1164. <button class="no">返 回</button>
  1165. <button class="yes">确 认</button>
  1166. </div>
  1167. <!-- 空购物车弹窗 -->
  1168. <div class="null-alert-window">
  1169. <img src="./photo/空空的.png" alt="" class="null-alert-img">
  1170. <div class="null-alert-text">您的购物车是空的,没有宝贝!</div>
  1171. <button class="null-re">返 回</button>
  1172. </div>
  1173. <!-- 空购物车背景 -->
  1174. <img src="./photo/包裹-空的.png" alt="" class="nullbg-img">
  1175. <div class="nullbg-text">您的购物车无宝贝!</div>
  1176. </body>
  1177. </html>

4.2 jQuery + Java Script 文件:

  1. // var delbtn1=document.querySelector('.del1btn1');
  2. // var delbtn2=document.querySelector('.del1btn2');
  3. // var delbtn3=document.querySelector('.del1btn3');
  4. // var delbtn4=document.querySelector('.del1btn4');
  5. //jquery 实现全选单选商品切换
  6. $(function(){
  7. $('.qx').change(function(){
  8. // 测试 点击全选输出true/false console.log($(this).prop('checked'));
  9. $('.check').prop('checked',$(this).prop('checked'));
  10. allprice();
  11. })
  12. $('.check').change(function(){
  13. if($(this).prop('checked')==true){
  14. allprice()
  15. }else if($(this).prop('checked')==false){
  16. allprice()
  17. }
  18. else if($('.check:checked').length==$('.check').length){
  19. $('.qx').prop('checked',true);
  20. }else{
  21. $('.qx').prop('checked',false);
  22. }
  23. })
  24. //add 变化,text()获取来的是string类型,自增会隐式转换
  25. $('.number-right').click(function(){
  26. var num=$(this).siblings('.number-center').text();
  27. num++;
  28. $(this).siblings('.number-center').text(num)
  29. //得到点击加号的物品的价格--->'¥xxx'
  30. var a=$(this).parent().parent().siblings('.price').children('div').text();
  31. console.log(a.length);
  32. //去掉¥符号
  33. var single_price=parseInt(a.substr(1,a.length-1))
  34. //赋值
  35. $(this).parent().parent().siblings('.allprice').find('.num').text(single_price*num)
  36. allprice()
  37. })
  38. $('.number-left').click(function(){
  39. if($(this).siblings('.number-center').text()=='1'){
  40. $(this).siblings('.number-center').text('1');
  41. $(this).parent().parent().siblings('.allprice').find('.num').text($(this).parent().parent().siblings('.price').children('div').text().substr(1,a.length-1))
  42. }else{
  43. var num=$(this).siblings('.number-center').text();
  44. num--;
  45. $(this).siblings('.number-center').text(num)
  46. //得到点击加号的物品的价格--->'¥xxx',注意此处可以使用parents()来代替parent().parent()
  47. var a=$(this).parent().parent().siblings('.price').children('div').text();
  48. //去掉¥符号
  49. var single_price=parseInt(a.substr(1,a.length-1))
  50. //赋值
  51. $(this).parent().parent().siblings('.allprice').find('.num').text(single_price*num)
  52. allprice()
  53. }
  54. })
  55. })
  56. //总价函数
  57. function allprice(){
  58. var sum=0;
  59. var price1=parseInt($('.heji1').siblings('.num').text())
  60. var price2=parseInt($('.heji2').siblings('.num').text())
  61. var price3=parseInt($('.heji3').siblings('.num').text())
  62. var price4=parseInt($('.heji4').siblings('.num').text())
  63. if($('.xz-1').children('.check').prop('checked')==true){
  64. var sum1=price1
  65. }else{
  66. sum1=0
  67. }
  68. if($('.xz-2').children('.check').prop('checked')==true){
  69. var sum2=price2
  70. }else{
  71. sum2=0
  72. }
  73. if($('.xz-3').children('.check').prop('checked')==true){
  74. var sum3=price3
  75. }else{
  76. sum3=0
  77. }
  78. if($('.xz-4').children('.check').prop('checked')==true){
  79. var sum4=price4
  80. }else{
  81. sum4=0
  82. }
  83. sum=sum1+sum2+sum3+sum4
  84. console.log(sum);
  85. $('.price-a').text(sum);
  86. }
  87. document.addEventListener('DOMContentLoaded',function(){
  88. var delbtn=document.querySelectorAll('.delbtn');
  89. var objects=document.querySelectorAll('.object');
  90. var main=document.querySelector('.main');
  91. var clearbtn=document.querySelector('.btn-clear');
  92. var searchbtn=document.querySelector('.search-img');
  93. var mask=document.querySelector('.mask');
  94. var alert=document.querySelector('.alert-window');
  95. var yes=document.querySelector('.yes');
  96. var no=document.querySelector('.no');
  97. var nullalert=document.querySelector('.null-alert-window');
  98. var nullbtn=document.querySelector('.null-re');
  99. var nullbgimg=document.querySelector('.nullbg-img');
  100. var nullbgtext=document.querySelector('.nullbg-text');
  101. var qx=document.querySelector('.qx');
  102. qx.addEventListener('click',function(){
  103. if(main.children.length==0){
  104. qx.checked=false;
  105. nullalert.style.display='block';
  106. mask.style.display='block'
  107. nullbtn.addEventListener('click',function(){
  108. nullalert.style.display='none';
  109. mask.style.display='none'
  110. nullbgimg.style.display='block'
  111. nullbgtext.style.display='block'
  112. })
  113. }
  114. })
  115. // del
  116. for(var i=0;i<delbtn.length;i++){
  117. delbtn[i].addEventListener('click',function(){
  118. // 测试用的
  119. // console.log(objects.length);
  120. // console.log(main.children.length);
  121. main.removeChild(this.parentNode.parentNode)
  122. allprice()
  123. if(main.children.length==0){
  124. nullbgimg.style.display='block'
  125. nullbgtext.style.display='block'
  126. qx.checked=false;
  127. }
  128. })
  129. }
  130. // prevent
  131. document.addEventListener('contextmenu',function(e){
  132. e.preventDefault();
  133. })
  134. document.addEventListener('selectstart',function(e){
  135. e.preventDefault();
  136. })
  137. // clear
  138. clearbtn.addEventListener('click',function(){
  139. if(main.children.length==0){
  140. nullalert.style.display='block';
  141. mask.style.display='block'
  142. nullbtn.addEventListener('click',function(){
  143. nullalert.style.display='none';
  144. mask.style.display='none'
  145. nullbgimg.style.display='block'
  146. nullbgtext.style.display='block'
  147. })
  148. }else{
  149. alert.style.display='block';
  150. mask.style.display='block'
  151. yes.addEventListener('click',function(){
  152. alert.style.display='none';
  153. mask.style.display='none';
  154. for(var i=0;i<objects.length;i++){
  155. main.removeChild(main.children[0])
  156. }
  157. allprice()
  158. qx.checked=false
  159. nullbgimg.style.display='block'
  160. nullbgtext.style.display='block'
  161. })
  162. no.addEventListener('click',function(){
  163. alert.style.display='none';
  164. mask.style.display='none';
  165. })
  166. }
  167. })
  168. //search-btn
  169. searchbtn.addEventListener('mouseenter',function(){
  170. this.src='./photo/搜索 (1).png'
  171. })
  172. searchbtn.addEventListener('mouseleave',function(){
  173. this.src='./photo/搜索.png'
  174. })
  175. })

🔊 创作不易,给个关注再走吧!

网站建设定制开发 软件系统开发定制 定制软件开发 软件开发定制 定制app开发 app开发定制 app开发定制公司 电商商城定制开发 定制小程序开发 定制开发小程序 客户管理系统开发定制 定制网站 定制开发 crm开发定制 开发公司 小程序开发定制 定制软件 收款定制开发 企业网站定制开发 定制化开发 android系统定制开发 定制小程序开发费用 定制设计 专注app软件定制开发 软件开发定制定制 知名网站建设定制 软件定制开发供应商 应用系统定制开发 软件系统定制开发 企业管理系统定制开发 系统定制开发