1 回答
TA贡献1807条经验 获得超9个赞
班级
const changes = {
"myClass1": "New unique Headline for myClass1",
"myClass2": "New unique Headline for myClass2"
};
Object.keys(changes)
.forEach(key => document.querySelectorAll("table th."+key)
.forEach(th => th.textContent = changes[key]));
<table>
<thead>
<tr>
<th class="myClass1">Current unique Headline for myClass1</th>
</tr>
<tr>
<th class="myClass2">Current unique Headline for myClass2</th>
</tr>
</thead>
内容:
const changes = {
"Current unique Headline for myClass1": "New unique Headline for myClass1",
"Current unique Headline for myClass3": "New unique Headline for myClass3"
};
[...document.querySelectorAll("th")]
.forEach(th => {
const text = changes[th.textContent];
if (text) th.textContent = text;
});
<table>
<thead>
<tr>
<th class="myClass1">Current unique Headline for myClass1</th>
</tr>
<tr>
<th class="myClass2">Current unique Headline for myClass2</th>
</tr>
<tr>
<th class="myClass3">Current unique Headline for myClass3</th>
</tr>
</thead>
添加回答
举报