我需要导出 .xls,但表中有一些我不需要的元素。我可以使用替换来删除所有包含“id”元素的 DOM 吗?
标签
<input id="id-1" value="111"><br>
<p">111</p>
<input id="id-2" value="222"><br>
<p">222</p>
<input id="id-3" value="3"><br>
<p">333</p>
<input id="id-4" value="4"><br>
<p">444</p>
<input id="id-5" value="4"><br>
<p">555</p>
</td>`
//i want to export like:
<td>
<br>
<p">111</p>
<br>
<p">222</p>
<br>
<p">333</p>
<br>
<p">444</p>
<br>
<p">555</p>
</td>```
i tried to use replace to search all id^* element but i cant remove the dom. i want to remove all DOM which included "id" elements in xls.
将返回 ID 与指定模式匹配的所有元素的 NodeList,然后从 DOM 中删除每个元素
const elementsToRemove = document.querySelectorAll('[id^="id"]');
elementsToRemove.forEach(element => element.remove());
<td>
<input id="id-1" value="111"><br>
<p>111</p>
<input id="id-2" value="222"><br>
<p>222</p>
<input id="id-3" value="3"><br>
<p>333</p>
<input id="id-4" value="4"><br>
<p>444</p>
<input id="id-5" value="4"><br>
<p>555</p>
</td>