<script>
function add(items) {
let parent = document.getElementsByTagName('tbody')[0].innerHTML;
let children = '';
let addValue = 0;
let addCount = 0;
for(let i of items){
children += '<tr><td>' + i.name + '</td><td>' + i.price.toString() + '</td><td><a href="javascript:void(0);">删除</a></td></tr>'
addValue += i.price;
addCount++;
}
parent += children;
document.getElementsByTagName('tbody')[0].innerHTML = parent;
let total = document.getElementsByTagName('tfoot')[0].childNodes[0].childNodes[1].innerText;
total = (Number(total.slice(0, total.indexOf('('))) + addValue).toFixed(2).toString() + '(' + (Number(total.slice(total.indexOf('(') + 1, total.indexOf('件'))) + addCount).toString() + '件商品)';
document.getElementsByTagName('tfoot')[0].childNodes[0].childNodes[1].innerText = total;
}
function bind() {
let parent = document.getElementsByTagName('tbody')[0];
let total = document.getElementsByTagName('tfoot')[0].childNodes[0].childNodes[1].innerText;
parent.addEventListener('click', (e) => {
if(e.target.nodeName == 'A'){
debugger;
let itemPrice = Number(e.target.parentNode.previousSibling.innerText);
total = (Number(total.slice(0, total.indexOf('('))) - itemPrice).toFixed(2).toString() + '(' + (Number(total.slice(total.indexOf('(') + 1, total.indexOf('件'))) - 1).toString() + '件商品)';
parent.removeChild(e.target.parentNode.parentNode);
document.getElementsByTagName('tfoot')[0].childNodes[0].childNodes[1].innerText = total;
}
})
}
add([{'name': '啊啊', 'price': 6},{'name': '啊啊1', 'price': 7},{'name': '啊啊123', 'price': 89}]);
bind();
</script>
```