我想把所有z-index
〈0的值替换为0,其中role
="columnheader"。我怎么用javascript或css实现这个呢?
电流输出
<div role="columnheader" style="z-index: 1; position: absolute; height: 50px; bottom: 0px; width: 60px; left: 18120px;" class="jqx-grid-column-header jqx-grid-column-header-bootstrap jqx-widget-header jqx-widget-header-bootstrap">
</div>
<div role="columnheader" style="z-index: 0; position: absolute; height: 50px; bottom: 0px; width: 60px; left: 18180px;" class="jqx-grid-column-header jqx-grid-column-header-bootstrap jqx-widget-header jqx-widget-header-bootstrap">
</div>
<div role="columnheader" style="z-index: -1; position: absolute; height: 50px; bottom: 0px; width: 60px; left: 18240px;" class="jqx-grid-column-header jqx-grid-column-header-bootstrap jqx-widget-header jqx-widget-header-bootstrap">
</div>
<div role="columnheader" style="z-index: -2; position: absolute; height: 50px; bottom: 0px; width: 60px; left: 18300px;" class="jqx-grid-column-header jqx-grid-column-header-bootstrap jqx-widget-header jqx-widget-header-bootstrap">
</div>
预期结果
<div role="columnheader" style="z-index: 1; position: absolute; height: 50px; bottom: 0px; width: 60px; left: 18120px;" class="jqx-grid-column-header jqx-grid-column-header-bootstrap jqx-widget-header jqx-widget-header-bootstrap">
</div>
<div role="columnheader" style="z-index: 0; position: absolute; height: 50px; bottom: 0px; width: 60px; left: 18180px;" class="jqx-grid-column-header jqx-grid-column-header-bootstrap jqx-widget-header jqx-widget-header-bootstrap">
</div>
<div role="columnheader" style="z-index: 0; position: absolute; height: 50px; bottom: 0px; width: 60px; left: 18240px;" class="jqx-grid-column-header jqx-grid-column-header-bootstrap jqx-widget-header jqx-widget-header-bootstrap">
</div>
<div role="columnheader" style="z-index: 0; position: absolute; height: 50px; bottom: 0px; width: 60px; left: 18300px;" class="jqx-grid-column-header jqx-grid-column-header-bootstrap jqx-widget-header jqx-widget-header-bootstrap">
</div>
2条答案
按热度按时间pbpqsu0x1#
在循环中使用属性选择器和并有条件地更改z索引:
或者你可以像这样在css中使用属性选择器:
yks3o0rb2#
您可以使用
querySelectorAll
命令查询所有元素,然后为forEach
循环中的每个元素应用z索引