使用jQuery實(shí)現(xiàn)購(gòu)物車(chē)結(jié)算功能
本文實(shí)例為大家分享了jQuery實(shí)現(xiàn)購(gòu)物車(chē)結(jié)算功能展示的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="js/jquery-1.8.3.js" ></script> <script> /*刪除*/ $(function(){ $(".blue").bind("click",function(){ $(this).parent().parent().remove(); totalPrice(); }); /*當(dāng)鼠標(biāo)離開(kāi)文本框時(shí),獲取當(dāng)前值,調(diào)用totalPrice()函數(shù)進(jìn)行結(jié)算*/ $(".shopping_product_list_5 input").bind("blur",function(){ var t = $(this).val(); totalPrice(); }); var allPrice = 0; var allReduce = 0; var allCount = 0; $("#myTableProduct tr").each(function(){ /*循環(huán)購(gòu)物車(chē)列表的每一行*/ var num = parseInt($(this).find(".shopping_product_list_5 input").val()); /*獲取文本框中數(shù)量值*/ var price = parseFloat($(this).find(".shopping_product_list_4 label").text()); /* 獲取商品價(jià)格*/ var total = price * num; allPrice += total; /*計(jì)算所有商品的總價(jià)格*/ /*獲取節(jié)省的金額*/ var reduce = parseFloat($(this).find(".shopping_product_list_3 label").text()) - parseFloat($(this).find(".shopping_product_list_4 label").text()); var reducePrice = reduce*num; allReduce +=reducePrice; /*獲取積分*/ var count = parseFloat($(this).find(".shopping_product_list_2 label").text()); allCount +=count; }); $("#product_total").text(allPrice.toFixed(2)); /*填寫(xiě)計(jì)算結(jié)果,其中利用toFixed()函數(shù)保留兩位小數(shù)*/ $("#product_save").text(allReduce.toFixed(2)); $("#product_integral").text(allCount.toFixed(2)); }); function totalPrice(){ var allPrice = 0; var allReduce = 0; var allCount = 0; $("#myTableProduct tr").each(function(){ var num = parseInt($(this).find(".shopping_product_list_5 input").val()); var price = parseFloat($(this).find(".shopping_product_list_4 label").text()); var total = price * num; allPrice += total; var reduce = parseFloat($(this).find(".shopping_product_list_3 label").text()) - parseFloat($(this).find(".shopping_product_list_4 label").text()); var reducePrice = reduce*num; allReduce +=reducePrice; var count = parseFloat($(this).find(".shopping_product_list_2 label").text()); allCount +=count; }); $("#product_total").text(allPrice.toFixed(2)); $("#product_save").text(allReduce.toFixed(2)); $("#product_integral").text(allCount.toFixed(2)); } </script> </head> <body> <div class="shopping_list_top">您已選購(gòu)以下商品</div> <div class="shopping_list_border"> <table width="100%" border="1px solid #ccc" > <tr class="shopping_list_title" > <td class="shopping_list_title_1">商品名</td> <td class="shopping_list_title_2">單品積分</td> <td class="shopping_list_title_3">市場(chǎng)價(jià)</td> <td class="shopping_list_title_4">當(dāng)當(dāng)價(jià)</td> <td class="shopping_list_title_5">數(shù)量</td> <td class="shopping_list_title_6">刪除</td> </tr> </table> <table width="100%" border="1px solid #ccc" id="myTableProduct"> <tr class="shopping_product_list" id="shoppingProduct_01"> <td class="shopping_product_list_1"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">私募(首部披露資本博弈秘密的金融...</a></td> <td class="shopping_product_list_2"><label>189</label></td> <td class="shopping_product_list_3">¥<label>32.00</label></td> <td class="shopping_product_list_4">¥<label>18.90 </label>(59折)</td> <td class="shopping_product_list_5"><input type="text" value="1"/></td> <td class="shopping_product_list_6"><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">刪除</a></td> </tr> <tr class="shopping_product_list" id="shoppingProduct_02"> <td class="shopping_product_list_1"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue"> 小團(tuán)圓(張愛(ài)玲最神秘小說(shuō)遺稿)</a></td> <td class="shopping_product_list_2"><label>173</label></td> <td class="shopping_product_list_3">¥<label>28.00</label></td> <td class="shopping_product_list_4">¥<label>17.30</label>(62折)</td> <td class="shopping_product_list_5"><input type="text" value="1"/></td> <td class="shopping_product_list_6"><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">刪除</a></td> </tr> <tr class="shopping_product_list" id="shoppingProduct_03"> <td class="shopping_product_list_1"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">不抱怨的世界(暢銷(xiāo)全球80國(guó)的世界...</a></td> <td class="shopping_product_list_2"><label>154</label></td> <td class="shopping_product_list_3">¥<label>24.80</label></td> <td class="shopping_product_list_4">¥<label>15.40</label> (62折)</td> <td class="shopping_product_list_5"><input type="text" value="2"/></td> <td class="shopping_product_list_6"><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">刪除</a></td> </tr> <tr class="shopping_product_list" id="shoppingProduct_04"> <td class="shopping_product_list_1"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">福瑪特雙桶洗衣機(jī)XPB20-07S</a></td> <td class="shopping_product_list_2"><label>358</label></td> <td class="shopping_product_list_3">¥<label>458.00</label></td> <td class="shopping_product_list_4">¥<label>358.00</label> (78折)</td> <td class="shopping_product_list_5"><input type="text" value="1"/></td> <td class="shopping_product_list_6"><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">刪除</a></td> </tr> <tr class="shopping_product_list" id="shoppingProduct_05"> <td class="shopping_product_list_1"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">PHP和MySQL Web開(kāi)發(fā) (原書(shū)第4版)</a></td> <td class="shopping_product_list_2"><label>712</label></td> <td class="shopping_product_list_3">¥<label>95.00</label></td> <td class="shopping_product_list_4">¥<label>71.20</label> (75折)</td> <td class="shopping_product_list_5"><input type="text" value="1"/></td> <td class="shopping_product_list_6"><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">刪除</a></td> </tr> <tr class="shopping_product_list" id="shoppingProduct_06"> <td class="shopping_product_list_1"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">法布爾昆蟲(chóng)記</a>(再買(mǎi)¥68.30即可參加“滿(mǎn)199元減10元現(xiàn)金”活動(dòng))</td> <td class="shopping_product_list_2"><label>10</label></td> <td class="shopping_product_list_3">¥<label>198.00</label></td> <td class="shopping_product_list_4">¥<label>130.70</label> (66折)</td> <td class="shopping_product_list_5"><input type="text" value="1"/></td> <td class="shopping_product_list_6"><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">刪除</a></td> </tr> </table> <div class="shopping_list_end"> <div><a id="removeAllProduct" href="javascript:void(0);" rel="external nofollow" >清空購(gòu)物車(chē)</a></div> <ul> <li class="shopping_list_end_1"><input name="" type="image" src="images/shopping_balance.gif"/></li> <li class="shopping_list_end_2">¥<label id="product_total"></label></li> <li class="shopping_list_end_3">商品金額總計(jì):</li> <li class="shopping_list_end_4">您共節(jié)省金額:¥<label class="shopping_list_end_yellow" id="product_save"></label><br/> 可獲商品積分:<label class="shopping_list_end_yellow" id="product_integral"></label> </li> </ul> </div> </div> </body> </html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- jQuery實(shí)現(xiàn)購(gòu)物車(chē)多物品數(shù)量的加減+總價(jià)計(jì)算
- jQuery實(shí)現(xiàn)加入購(gòu)物車(chē)飛入動(dòng)畫(huà)效果
- 基于JQuery實(shí)現(xiàn)的類(lèi)似購(gòu)物商城的購(gòu)物車(chē)
- JQuery實(shí)現(xiàn)的購(gòu)物車(chē)功能(可以減少或者添加商品并自動(dòng)計(jì)算價(jià)格)
- 純jquery實(shí)現(xiàn)模仿淘寶購(gòu)物車(chē)結(jié)算
- jQuery實(shí)現(xiàn)購(gòu)物車(chē)計(jì)算價(jià)格功能的方法
- jQuery實(shí)現(xiàn)購(gòu)物車(chē)數(shù)字加減效果
- jQuery實(shí)現(xiàn)類(lèi)似淘寶購(gòu)物車(chē)全選狀態(tài)示例
- jQuery+HTML5加入購(gòu)物車(chē)代碼分享
- jQuery仿天貓實(shí)現(xiàn)超炫的加入購(gòu)物車(chē)
相關(guān)文章
jquery遍歷table的tr獲取td的值實(shí)現(xiàn)方法
下面小編就為大家?guī)?lái)一篇jquery遍歷table的tr獲取td的值實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-05-05Easyui 關(guān)閉jquery-easui tab標(biāo)簽頁(yè)前觸發(fā)事件的解決方法
這篇文章主要介紹了Easyui 關(guān)閉jquery-easui tab標(biāo)簽頁(yè)前觸發(fā)事件 ,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-04-04jQuery實(shí)現(xiàn)簡(jiǎn)單五子棋游戲
這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)簡(jiǎn)單五子棋游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05jQuery實(shí)現(xiàn)多級(jí)聯(lián)動(dòng)下拉列表查詢(xún)框
這篇文章主要為大家介紹了jQuery實(shí)現(xiàn)多級(jí)聯(lián)動(dòng)下拉列表查詢(xún)框,感興趣的小伙伴們可以參考一下2016-01-01jquery 表單驗(yàn)證之通過(guò) class驗(yàn)證表單不為空
在開(kāi)發(fā)系統(tǒng)時(shí),往往都有某些表單數(shù)據(jù)為必填項(xiàng),若用jQuery通過(guò)ID去驗(yàn)證,不僅會(huì)影響效率,還會(huì)有所遺漏,不易于后期維護(hù)。 本章將介紹如何利用jQuery,通過(guò)為表單配置class進(jìn)行統(tǒng)一驗(yàn)證。2015-11-11