1 回答
TA贡献1797条经验 获得超6个赞
您可以使用slice方法和querySelectorAll>来做到这一点span。替换标题的文本。这将是Title 4
首先,我们将获得您的跨度的实际textContent,然后我们使用 0,7 中的切片,它将 Just title excluding (#1843)。
最后,我们将textContent再次使用 span 中设置新标题。
运行下面的代码片段以查看它是否正常工作。
function cutId() {
//get all tds
let allTds = document.querySelectorAll(".vpe-img-td span");
//Foreach Loop
allTds.forEach(function(data) {
//Get the text
let spanText = data.textContent
//Slice the title
let slice = spanText.slice(0, 7)
//Set title again
data.textContent = spanText.replace(spanText, slice)
})
}
cutId();
<div class="vpe_table_responsive">
<table class="vpe_table" id="vpe_table">
<thead>
<tr>
<th>Title</th>
<th>Title</th>
<th>Title</th>
<th>Title</th>
</tr>
</thead>
<tbody class="pagination_row">
<tr class="vpe_row variant-1843" data-tobeshown="no">
<td data-title="Title" id="vpe-title-td-1843" class="vpe-img-td">
<span>Talla 1 (#1843)</span>
</td>
<td data-title="Title" id="vpe-title-td-1843" class="vpe-img-td">
<span>Talla 2 (#8888)</span>
</td>
<td data-title="Title" id="vpe-title-td-1843" class="vpe-img-td">
<span>Talla 3 (#8216)</span>
</td>
<td data-title="Title" id="vpe-title-td-1843" class="vpe-img-td">
<span>Talla 4 (#1588)</span>
</td>
</tr>
</tbody>
</table>
</div>
添加回答
举报
