首页 > 解决方案 > 获取具有特定类而不是特定样式的元素

问题描述

使用纯 JavaScript,如何获取所有没有 CSS 样式的元素?我需要获取未隐藏的表格行,并且它们没有附加明确的“显示”。

<table>
<tr class='form-row-links'>
Stuff...
</tr>
</table>

document.querySelectorAll('.form-row-links[style="display:is_not_none;"]') //pseudocode, of course :)

css 样式display=none在页面初始化后应用到<tr>元素。

标签: javascript

解决方案


感谢@Ry- 将我指向getComputedStyle

我实际上认为我可以只声明该行的初始样式,然后它可能会被我的 JavaScript 用“none”或不覆盖:

<table>
<tr class='form-row-links' style='display:table-row;'>
Stuff...
</tr>
</table>

document.querySelectorAll('.form-row-links[style="display:table-row;"]')

推荐阅读