获得节点信息
js
let node = this.$refs["tbody"]
let nodeChild = node.childNodes
let nodeInner = nodeChild.innerText
let node = this.$refs["tbody"]
let nodeChild = node.childNodes
let nodeInner = nodeChild.innerText
获得节点的子节点
js
node.childNodes[]
node.childNodes[n]
node.childNodes[]
node.childNodes[n]
给节点添加style
js
node.classList.add('className')
node.classList.add('className')
替换节点内容
js
node.innerText = '添加的内容'
node.innerText = '添加的内容'
- 实例
js
for (let n = 0; n < this.$refs["tbody"].childNodes.length; n++) {
let tr = this.$refs["tbody"].childNodes[n]
for (let n_c = 0; n_c < tr.childNodes.length; n_c++) {
let td = tr.childNodes[n_c].innerText
if (td == '-') {
this.$refs["tbody"].childNodes[n].childNodes[n_c].classList.add('number_0_style')
this.$refs["tbody"].childNodes[n].childNodes[n_c].innerText = '————'
}
}
}
for (let n = 0; n < this.$refs["tbody"].childNodes.length; n++) {
let tr = this.$refs["tbody"].childNodes[n]
for (let n_c = 0; n_c < tr.childNodes.length; n_c++) {
let td = tr.childNodes[n_c].innerText
if (td == '-') {
this.$refs["tbody"].childNodes[n].childNodes[n_c].classList.add('number_0_style')
this.$refs["tbody"].childNodes[n].childNodes[n_c].innerText = '————'
}
}
}