master
chen 2021-09-28 16:23:41 +08:00
parent f34e26d6d6
commit 651eac1471
1 changed files with 12 additions and 104 deletions

View File

@ -73,10 +73,13 @@
<div class="whoil-1 backFF"> <div class="whoil-1 backFF">
<div class="all">全部商品(20)</div> <div class="all">全部商品(20)</div>
<!-- 选择 --> <!-- 选择 -->
<div>
<div></div>
</div>
<table class="table-cbox" border="0" cellspacing="0"> <table class="table-cbox" border="0" cellspacing="0">
<thead> <thead>
<tr> <tr>
<th><input type="checkbox" id="ckAll" onclick="checkAll()">全选</th> <th><input type="checkbox" id="ckAll">全选</th>
<th>商品</th> <th>商品</th>
<th></th> <th></th>
<th>单价</th> <th>单价</th>
@ -89,7 +92,7 @@
<tr class="inline" valign="top"> <tr class="inline" valign="top">
<td> <td>
<div> <div>
<input type="checkbox" name="ck" onclick="check()"> <input type="checkbox" name="ck">
<img src="../../img/images/1-1.png" alt="图片丢失" title="购物车图片一" /> <img src="../../img/images/1-1.png" alt="图片丢失" title="购物车图片一" />
</div> </div>
</td> </td>
@ -100,18 +103,18 @@
<td>¥188.00</td> <td>¥188.00</td>
<td> <td>
<div> <div>
<div class="reduce" onclick="reduceCount(this)">-</div> <div class="reduce">-</div>
<input type="text" value="3" class="count-input"> <input type="text" value="3" class="count-input">
<div class="add" onclick="addCount(this)">+</div> <div class="add">+</div>
</div> </div>
</td> </td>
<td>¥564.00</td> <td>¥564.00</td>
<td class="delete" onclick="del(this)">删除</td> <td class="delete">删除</td>
</tr> </tr>
<tr class="inline" valign="top"> <tr class="inline" valign="top">
<td> <td>
<div> <div>
<input type="checkbox" name="ck" onclick="check()"> <input type="checkbox" name="ck">
<img src="../../img/images/1-1.png" alt="图片丢失" title="购物车图片一" /> <img src="../../img/images/1-1.png" alt="图片丢失" title="购物车图片一" />
</div> </div>
</td> </td>
@ -122,13 +125,13 @@
<td>¥188.00</td> <td>¥188.00</td>
<td> <td>
<div> <div>
<div class="reduce" onclick="reduceCount(this)">-</div> <div class="reduce">-</div>
<input type="text" value="3" class="count-input"> <input type="text" value="3" class="count-input">
<div class="add" onclick="addCount(this)">+</div> <div class="add">+</div>
</div> </div>
</td> </td>
<td>¥564.00</td> <td>¥564.00</td>
<td class="delete" onclick="del(this)">删除</td> <td class="delete">删除</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -226,101 +229,6 @@
// } // }
} }
sixSwiper() sixSwiper()
//获取元素
var ckAll = document.getElementById('ckAll');
var cks = document.getElementsByName('ck');
var trs = document.getElementsByClassName('inline');
var allCount = document.getElementById('allCount');
var allPrice = document.getElementById('allPrice');
var countInput = document.getElementsByClassName('count-input');
var accounts = document.getElementById("accounts");
// 结算
function accounts() {
var sum = 0;
}
function accounts() {
accounts.style.display = "block";
alert("")
accounts.innerHTML = str;
}
//计算总价
function sumPrice() {
var sum = 0;
for (var i = 0; i < cks.length; i++) {
if (cks[i].checked == true) {
var p = Number(trs[i].children[4].innerHTML);
sum += p;
}
}
allPrice.innerHTML = sum.toFixed(2);
}
//计算每一行的总价
function inlinePrice() {
for (var i = 0; i < trs.length; i++) {
//获取每一行单价
var price = Number(trs[i].children[2].innerHTML);
//获取数量
var num = Number(trs[i].children[3].children[1].value);
//小计
trs[i].children[4].innerHTML = (price * num).toFixed(2);
}
}
//数量增加
function addCount(e) {
var num = parseInt(e.previousElementSibling.value);
// 最大数量
if (num > 98) {
alert("不能再多了");
return;
}
//数量加1
e.previousElementSibling.value = num + 1;
inlinePrice();
sumPrice();
// sumCount();
}
//数量递减
function reduceCount(e) {
var num = parseInt(e.nextElementSibling.value);
if (num <= 0) {
alert("不能再减了");
return;
}
e.nextElementSibling.value = num - 1;
inlinePrice();
sumPrice();
// sumCount();
}
//全选和反选
function checkAll() {
for (var i = 0; i < cks.length; i++) {
cks[i].checked = ckAll.checked;
}
sumPrice();
// sumCount();
}
//复选框
function check() {
for (var i = 0; i < cks.length; i++) {
if (cks[i].checked == false) {
ckAll.checked = false;
sumPrice();
// sumCount();
return;
}
}
ckAll.checked = true;
sumPrice();
sumCount();
}
//单行删除
function del(e) {
e.parentElement.parentElement.remove();
sumPrice();
// sumCount();
}
</script> </script>
<!-- 底部导航 --> <!-- 底部导航 -->
<div class="foot-nav-box"> <div class="foot-nav-box">