
最好能给出代码,谢谢!
<!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>Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...