关注
我的: 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
相关推荐
09-12 14:49
南方科技大学 运营 点赞 评论 收藏
分享

点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 从顶到拉给所有面过的公司评分 #
17011次浏览 155人参与
# 机械人春招想让哪家公司来捞你? #
357095次浏览 3108人参与
# 为了求职,我做过的疯狂伪装 #
11644次浏览 206人参与
# 晒晒你的中秋福利 #
14922次浏览 96人参与
# 职场破冰,你们都聊什么? #
6578次浏览 66人参与
# bilibili求职进展汇总 #
87212次浏览 793人参与
# 工作压力大怎么缓解 #
104940次浏览 1050人参与
# 大家实习每天都在干啥 #
88839次浏览 518人参与
# 广联达求职进展汇总 #
10829次浏览 50人参与
# 机械人怎么评价今年的华为 #
208731次浏览 1524人参与
# 秋招OC许愿 #
346037次浏览 2525人参与
# 你的公司给实习生发中秋礼物吗 #
1455次浏览 26人参与
# 你面试被问到过哪些不会的问题? #
20408次浏览 783人参与
# 聊聊这家公司值得去吗 #
555967次浏览 3693人参与
# 电网笔面经互助 #
46545次浏览 431人参与
# 宣讲会你有哪些意向不到的收获 #
1081次浏览 20人参与
# 秋招的嫡长offer #
28257次浏览 266人参与
# 你觉得早上几点上班合适? #
82395次浏览 330人参与
# 秋招报数:你投了多少家公司? #
28080次浏览 290人参与
# 实习要如何选择和准备? #
114641次浏览 1436人参与