• jQuery实现的简易购物车增删合计



    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>简易购物车增删合计</title>
    <script type="text/javascript" src="jquery-1.4.2.js"></script>
    <script type="text/javascript">
    $(function(){
    $(".add").click(function(){
    var t=$(this).parent().find('input[class*=text_box]');
    t.val(parseInt(t.val())+1)
    setTotal();
    })
    $(".min").click(function(){
    var t=$(this).parent().find('input[class*=text_box]');
    t.val(parseInt(t.val())-1)
    if(parseInt(t.val())<0){
    t.val(0);
    }
    setTotal();
    })
    function setTotal(){
    var s=0;
    $("#tab td").each(function(){
    s=s +parseInt($(this).find('input[class*=text_box]').val())
    *parseFloat($(this).find('span[class*=price]').text());
    });
    $("#total").html(s.toFixed(2));
    }
    setTotal();
    })
    </script>
    </head>
    <body>
    <table id="tab">
    <tr>
    <td>
    <span>单价:</span><span class="price">1.50</span>
    <input class="min" name="" type="button" value="-" />
    <input class="text_box" name="" type="text" value="0" readonly="readonly" />
    <input class="add" name="" type="button" value="+" /></td>
    </tr>
    <tr>
    <td>
    <span>单价:</span><span class="price">3.95</span>
    <input class="min" name="" type="button" value="-" />
    <input class="text_box" name="" type="text" value="0" />
    <input class="add" name="" type="button" value="+" /></td>
    </tr>
    </table>
    <p>总价:<label id="total"></label></p>
    </body>
    </html>

  • 相关阅读:
    leetcode41
    leetcode32
    leetcode312
    leetcode10
    leetcode85
    leetcode124
    leetcode301
    leetcode84
    一文读懂机器学习大杀器XGBoost原理
    【干货】机器学习中的五种回归模型及其优缺点
  • 原文地址:https://www.cnblogs.com/ll-taj/p/6118509.html
Copyright © 2020-2023  润新知