首页 > 代码库 > 模拟购物车表格
模拟购物车表格
<div id="arae">
<table border="1" style="text-align: center">
<thead>
<th>商品编号</th>
<th>商品名称</th>
<th>商品数量</th>
<th>商品单价</th>
<th>商品总价</th>
<th>操作</th>
</thead>
<tbody id="tbody">
<tr>
<td>1</td>
<td>iphone4</td>
<td><input type="button" value=http://www.mamicode.com/" + " class="ad"><span class="count">0</span><input type="button" value=http://www.mamicode.com/" - " class="sb"></td>
<td class="danJia">2000</td>
<td><span class="price">0</span></td>
<td><input type="button" value=http://www.mamicode.com/"删除" class="delete"></td>
</tr>
<tr>
<td>2</td>
<td>iphone4s</td>
<td><input type="button" value=http://www.mamicode.com/" + " class="ad"><span class="count">0</span><input type="button" value=http://www.mamicode.com/" - " class="sb"></td>
<td>2200</td>
<td><span class="price">0</span></td>
<td><input type="button" value=http://www.mamicode.com/"删除" class="delete"></td>
</tr>
<tr>
<td>3</td>
<td>iphone5</td>
<td><input type="button" value=http://www.mamicode.com/" + " class="ad"><span class="count">0</span><input type="button" value=http://www.mamicode.com/" - " class="sb"></td>
<td>2400</td>
<td><span class="price">0</span></td>
<td><input type="button" value=http://www.mamicode.com/"删除" class="delete"></td>
</tr>
<tr>
<td>4</td>
<td>iphone6</td>
<td><input type="button" value=http://www.mamicode.com/" + " class="ad"><span class="count">0</span><input type="button" value=http://www.mamicode.com/" - " class="sb"></td>
<td>4000</td>
<td><span class="price">0</span></td>
<td><input type="button" value="http://www.mamicode.com/删除" class="delete"></td>
</tr>
<tr>
<td>5</td>
<td>iphone7</td>
<td><input type="button" value="http://www.mamicode.com/+" class="ad"><span class="count">0</span><input type="button" value="http://www.mamicode.com/-" class="sb"></td>
<td>7000</td>
<td><span class="price">0</span></td>
<td><input type="button" value="http://www.mamicode.com/删除" class="delete"></td>
</tr>
</tbody>
<tfoot>
<tr>
<td>商品总数</td>
<td><span class="allCount">0</span></td>
<td>商品总价</td>
<td><span class="allPrice">0</span></td>
<td><input type="button" value="http://www.mamicode.com/清空购物车" class="allDelete"></td>
</tr>
</tfoot>
</table>
</div>
#arae{
width: 550px;
margin: 0 auto;
float: left;
}
#arae span{
color: black;
text-decoration: none;
}
$(‘#tbody‘).on(‘click‘,‘.delete‘,function(){
$(this).parent().parent().empty();
showAllCount();
showAllPrice();
});
$(‘.allDelete‘).on(‘click‘,function(){
$(‘#tbody‘).empty();
});
$(‘#tbody‘).on(‘click‘,‘.ad‘,function(){
var a = $(this).next(‘.count‘).text();
a++;
$(this).next(‘.count‘).text(a);
var b = +$(this).parent().next(‘td‘).text();
s = a*b;
$(this).parent().next(‘td‘).next(‘td‘).children().text(s);
showAllCount();
showAllPrice();
}).on(‘click‘,‘.sb‘,function(){
var a = $(this).prev(‘.count‘).text();
a--;
$(this).prev(‘.count‘).text(a);
var b = +$(this).parent().next(‘td‘).text();
s = a*b;
$(this).parent().next(‘td‘).next(‘td‘).children().text(s);
showAllCount();
showAllPrice();
});
function showAllCount(){
var allSum = 0;
$(‘.count‘).each(function(){
allSum = allSum + (+$(this).text());
$(‘.allCount‘).text(allSum);
});
}
function showAllPrice(){
var allSum = 0;
$(‘.price‘).each(function(){
allSum = allSum + (+$(this).text());
$(‘.allPrice‘).text(allSum);
});
}
模拟购物车表格
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。