我正在寻找一种通过部分内部 html 获取元素 id 的方法
例如,我有这个模板
<div id="unpredictable-id1">
<label>
<span id="unpredictable-id1"> (unpredictable text) </span> <!-- this span have has the same id than div but has unpredictable content -->
<span>persistant text</span> <!-- this span have no id, no class, no identifier -->
</label>
</div>
我猜不出<div>id(没有后缀,没有前缀,没有其他属性......)我必须获取元素的唯一方法是通过内部跨度中的文本(我之前可以找到的文本)
我尝试过类似的东西identifiers = document.querySelectorAll("[textContent*='persistant text']").id;但总是返回“未定义”
有人有线索吗?
森林海
相关分类