找了半天,就是出不来,帮忙看看各位
var cartTable = document.getElementById('cartTable');
//.rows,专门获取tr
var tr = cartTable.children[1].rows;
var checkInputs = document.getElementsByClassName('check');
var checkAllInputs = document.getElementsByClassName('check-all');
var selectedTotal = document.getElementById('selectedTotal');
var priceTotal = document.getElementById('priceTotal');
//计算
function getTotal() {
var seleted = 0;
var price = 0;
for (var i = 0, len = tr.length; i < len; i++) {
if (tr[i].getElementsByTagName('input')[0].checked) {
seleted += parseInt(tr[i].getElementsByTagName('input')[1].value);
price += parseFloat(tr[i].cells[4].innerHTML);
}
}
selectedTotal.innerHTML = seleted;
priceTotal.innerHTML = price.toFixed(2);
}
for (var i = 0 , len = checkInputs.length; i < len; i++) {
checkInputs[i].onclick = function () {
getToal();
}
}
}