jquery商品计算器,无法获取,[总计]价格?
高洛峰
高洛峰 2016-10-25 09:28:51
[JavaScript讨论组]

1.png

最好能给出代码,谢谢!

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="">
<meta name="keywords" content="">
<title>商品计算器,购物车模块一</title>
<!-- <script type="text/javascript" src="jquery-1.10.1.min.js"></script> -->
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<style type="text/css">
*{
    /*line-height: 30px;*/
    padding:0px;
    margin: 0px;
}
table{
    text-align: center;
    margin: 30px;
}
td,th{
    padding:8px;
}
input{
    width:120px;
}
</style>
</head>
<script type="text/javascript">
$(document).ready(function() {
    function aa(){
        var price;
        for(i=0;i<$('tr').size()-2;i++){
            // 小计函数
            var price=$('.price').eq(i).val()*$('.num').eq(i).val();
            $('.subtotal').eq(i).text(price);
            // price=parseInt(price)+parseInt(price);
        }
        // console.log(price);
   }
        // 总计函数
        // $('.total_price').text(total);
        // price=price+price;
    $('input').change(function(){
      aa();
    })
});
</script>


<body>
<table border="1"  width="600" cellspacing="0" cellpadding="0" bordercolor="#b2b2b2" style="border-collapse:collapse" >
    <tr>
        <th>商品</th>
        <th>单价(元/件)</th>
        <th>数量(件)</th>
        <th>小计(元)</th>
    </tr>
    <tr>
        <td>iPad</td>
        <td><input type="text" class="price" value="0"></td>
        <td><input type="text" class="num" value="0"></td>
        <td class="subtotal">0</td>
    </tr>

  <tr>
        <td>iPhone</td>
        <td><input type="text" class="price" value="0"></td>
        <td><input type="text" class="num" value="0"></td>
        <td class="subtotal">0</td>
    </tr>

  <tr>
        <td>iMac</td>
        <td><input type="text" class="price" value="0"></td>
        <td><input type="text" class="num" value="0"></td>
        <td class="subtotal">0</td>
    </tr>
    <tr>
     <td colspan="3">总计:</td>
    <td class="total_price"></td>
    </tr>

</table>

</body>
</html>


高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回复(1)
三叔
nbsp;html>



    
    
    
    商品计算器,购物车模块一
    
    
    
    
                                                                                                                                                                                                                                                                                                                                        
商品单价(元/件)数量(件)小计(元)
iPad                                                            0
iPhone                                                            0
iMac                                                            0
总计:


热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号