//获取元素 var check = document.getElementsByClassName('check'); var checkAll = document.getElementsByClassName('checkAll'); var table = document.getElementById('box'); var tr = document.getElementsByTagName('tr'); var num = document.getElementsByClassName('num')[0]; var priTotal = document.getElementById('priTotal'); var ps = document.getElementsByClassName('price_small'); //计算函数,方法累加,定义变量初值 function getTotal() { var select = 0; var priceTotal = 0; for (var i = 0, len = tr.length; i < len; i++) { if (tr[i].getElementsByTagName('input')[0].checked) { select += parseInt(tr[i].getElementsByTagName('input')[1].value); priceTotal += parseFloat(ps[i - 1].innerHTML); } } num.innerHTML = select; priTotal.innerHTML = priceTotal.toFixed(2); } // 点击单选框事件 for(i = 0;i < check.length;i++){ check[i].onclick = function () { if(this.className === 'checkAll check'){ for(j = 0;j < check.length;j++){ check[j].checked = this.checked; } } getTotal(); } }
获取的值没有