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();
}
}
}
你的最下面的代码写错了getToal();应该是getTotal() 下次你在遇到这样的问题你就点F12然后把选中点一下就可以看到代码那一行出错了。
最下面多了一个}