最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用jQuery實(shí)現(xiàn)購(gòu)物車結(jié)算功能

 更新時(shí)間:2017年08月15日 08:41:20   投稿:lijiao  
這篇文章主要為大家詳細(xì)介紹了使用jQuery實(shí)現(xiàn)購(gòu)物車結(jié)算功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了jQuery實(shí)現(xiàn)購(gòu)物車結(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)離開文本框時(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)物車列表的每一行*/
    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)); /*填寫計(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">不抱怨的世界(暢銷全球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">?,斕仉p桶洗衣機(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開發(fā) (原書第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">法布爾昆蟲記</a>(再買¥68.30即可參加“滿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)物車</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í)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • JQuery 風(fēng)格的HTML文本轉(zhuǎn)義

    JQuery 風(fēng)格的HTML文本轉(zhuǎn)義

    astinus開發(fā)過(guò)程中,我自己就在不斷的使用。有次貼了一些JS代碼進(jìn)去,于是頁(yè)面顯示錯(cuò)誤。顯然,把源代碼直接放進(jìn)html文本了——好吧,從05年轉(zhuǎn)去做網(wǎng)游以后,一直沒(méi)有正經(jīng)的做過(guò)web了。
    2009-07-07
  • html5的自定義data-*屬性和jquery的data()方法的使用示例

    html5的自定義data-*屬性和jquery的data()方法的使用示例

    人們總喜歡往HTML標(biāo)簽上添加自定義屬性來(lái)存儲(chǔ)和操作數(shù)據(jù),這就是為什么在HTML5規(guī)范里增加了一個(gè)自定義data屬性,你可以拿它做很多有用的事情
    2013-08-08
  • JQuery對(duì)表格進(jìn)行操作的常用技巧總結(jié)

    JQuery對(duì)表格進(jìn)行操作的常用技巧總結(jié)

    這篇文章主要介紹了JQuery對(duì)表格進(jìn)行操作的常用技巧,需要的朋友可以參考下
    2014-04-04
  • jQuery實(shí)現(xiàn)加入購(gòu)物車飛入動(dòng)畫效果

    jQuery實(shí)現(xiàn)加入購(gòu)物車飛入動(dòng)畫效果

    當(dāng)您在電商購(gòu)物網(wǎng)站瀏覽中意的商品時(shí),您可以點(diǎn)擊頁(yè)面中的“加入購(gòu)物車”按鈕即可將商品加入的購(gòu)物車中。本文介紹借助一款基于jQuery的動(dòng)畫插件,點(diǎn)擊加入購(gòu)物車按鈕時(shí),實(shí)現(xiàn)商品將飛入到右側(cè)的購(gòu)物車中的效果。
    2015-03-03
  • jquery多瀏覽器捕捉回車事件代碼

    jquery多瀏覽器捕捉回車事件代碼

    最近我們網(wǎng)站做一個(gè)合作項(xiàng)目要求在頁(yè)面中捕捉回車事件,經(jīng)過(guò)好多測(cè)試找到這個(gè)
    2010-06-06
  • jQuery使用fadeout實(shí)現(xiàn)元素漸隱效果的方法

    jQuery使用fadeout實(shí)現(xiàn)元素漸隱效果的方法

    這篇文章主要介紹了jQuery使用fadeout實(shí)現(xiàn)元素漸隱效果的方法,實(shí)例分析了jQuery中fadeout方法的使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-03-03
  • jQuery實(shí)現(xiàn)移動(dòng)端扭蛋機(jī)抽獎(jiǎng)

    jQuery實(shí)現(xiàn)移動(dòng)端扭蛋機(jī)抽獎(jiǎng)

    這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)移動(dòng)端扭蛋機(jī)抽獎(jiǎng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-11-11
  • jquery做個(gè)日期選擇適用于手機(jī)端示例

    jquery做個(gè)日期選擇適用于手機(jī)端示例

    本篇文章主要介紹了jquery做個(gè)日期選擇適用于手機(jī)端示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-01-01
  • 讀jQuery之三(構(gòu)建選擇器)

    讀jQuery之三(構(gòu)建選擇器)

    前面兩篇已經(jīng)道明了jQuery的核心框架。弄清楚了jQuery對(duì)象的組成,以及如何用extend方法來(lái)擴(kuò)展庫(kù)。鏈?zhǔn)讲僮?也僅僅是方法體內(nèi)返回this。
    2011-06-06
  • jQuery中的ready函數(shù)與window.onload誰(shuí)先執(zhí)行

    jQuery中的ready函數(shù)與window.onload誰(shuí)先執(zhí)行

    這篇文章主要介紹了jquery中ready函數(shù)與window.onload函數(shù)的區(qū)別,別講解了他們各自執(zhí)行的時(shí)機(jī),通俗易懂,需要的朋友可以參考下。
    2016-06-06

最新評(píng)論

徐水县| 正安县| 巴中市| 上饶市| 西藏| 定边县| 团风县| 桦川县| 沅陵县| 韶山市| 股票| 秦皇岛市| 辽阳县| 耿马| 井研县| 资源县| 迁西县| 徐水县| 荆门市| 光泽县| 嘉黎县| 上蔡县| 成都市| 呼伦贝尔市| 伊春市| 双桥区| 靖远县| 丰县| 兰西县| 安丘市| 上饶市| 齐河县| 沂源县| 阳新县| 灌云县| 黄浦区| 大足县| 三河市| 永和县| 离岛区| 景洪市|