关注
我的: 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
相关推荐
点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 牛客新年AI问运 #
6355次浏览 110人参与
# 工作中的卑微时刻 #
33405次浏览 199人参与
# 牛客AI体验站 #
16221次浏览 286人参与
# 多益网络工作体验 #
63134次浏览 306人参与
# 有必要和同事成为好朋友吗? #
984次浏览 21人参与
# 正在实习的碎碎念 #
1644846次浏览 13716人参与
# 面试中的破防瞬间 #
1190161次浏览 11027人参与
# 工作一周年分享 #
52318次浏览 274人参与
# 滴!实习打卡 #
786491次浏览 6841人参与
# 秋招吐槽大会 #
304252次浏览 1523人参与
# 机械人的薪资开到多少,才适合去? #
165017次浏览 571人参与
# 你最满意的offer薪资是哪家公司? #
71373次浏览 353人参与
# 大学最后一个寒假,我想…… #
89264次浏览 809人参与
# 你怎么看待AI面试 #
145980次浏览 786人参与
# 哪些公司真双非友好? #
62876次浏览 268人参与
# OC/开奖 #
411245次浏览 2282人参与
# 为了实习逃课值吗? #
65758次浏览 526人参与
# 如果可以选,你最想从事什么工作 #
721923次浏览 4870人参与
# 重来一次,你会对开始求职的自己说 #
32802次浏览 388人参与
# 如何提高实习转正率? #
86512次浏览 504人参与