我的: class CountInfo { constructor() { let tfoot = document.getElementsByTagName("tfoot")[0] let countInfoTag = tfoot.children[0].children[1] let tmp = countInfoTag.innerHTML.match(/\d+/g) let countInfo = { price: 0, num: 0 } countInfo.price = (tmp[0] - 0) + (tmp[1] - 0) * 0.01 countInfo.num = tmp[2] - 0 this.countInfoTag = countInfoTag this.countInfo = countInfo } delete(price) { this.countInfo.num-- this.countInfo.price = this.countInfo.price - price this.countInfoTag.innerHTML = `${this.countInfo.price.toFixed(2)}(${this.countInfo.num}件商品)` } add(price) { this.countInfo.num++ this.countInfo.price = this.countInfo.price + price this.countInfoTag.innerHTML = `${this.countInfo.price.toFixed(2)}(${this.countInfo.num}件商品)` } } bind() function add(items) { let tr = document.createElement("tr") tr.innerHTML = `<td>${items.name}</td><td>${items.price.toFixed(2)}</td><td><a href="javascript:void(0);">删除</a></td>` let tbody = document.getElementsByTagName("tbody")[0] tbody.appendChild(tr) tr.children[2].children[0].onclick = click const countInfo = new CountInfo() countInfo.add(items.price) } function bind() { let tags = document.getElementsByTagName("a") const LEN = tags.length for (let i = 0; i < LEN; i++) { tags[i].onclick = click } } function click(e) { const countInfo = new CountInfo() let tr = e.srcElement.parentElement.parentElement countInfo.delete(tr.children[1].innerHTML - 0) tr.remove() }
点赞 1

相关推荐

小红书 后端开发 总包n+8w+期权
点赞 评论 收藏
分享
10-09 09:39
门头沟学院 C++
HHHHaos:这也太虚了,工资就一半是真的
点赞 评论 收藏
分享
10-07 20:48
门头沟学院 Java
不敢追175女神:可能是实习上着班想到后面还要回学校给导师做牛马,看着身边都是21-25的年纪,突然emo了了
点赞 评论 收藏
分享
11-28 17:48
中山大学 C++
点赞 评论 收藏
分享
牛客网
牛客企业服务