Jquery 每个div的增量z索引

Jquery 每个div的增量z索引,jquery,html,css,z-index,Jquery,Html,Css,Z Index,我正在设计一个div相互重叠的设计,我为类的每个成员分别增加z-index1。我觉得用jquery有更好的方法 我想要的是类部分的每个div都有一个z-index大于上一个,但不会被不是特定类成员的div抛出,例如 <div class="section" style="z-index:1">Lorem</div> <div class="section" style="z-index:2">Lorem</div> <div id="OutO

我正在设计一个div相互重叠的设计,我为类的每个成员分别增加
z-index
1。我觉得用
jquery
有更好的方法

我想要的是类
部分的每个div都有一个
z-index
大于上一个,但不会被不是特定类成员的div抛出,例如

<div class="section" style="z-index:1">Lorem</div>
<div class="section" style="z-index:2">Lorem</div>
<div id="OutOfPlaceDiv">Foo</div>
<div class="section" style="z-index:3">Lorem</div>
Lorem
洛勒姆
福
洛勒姆

使用
每个
方法迭代该类的元素

$('.section').each(function(index) {
  $(this).css("z-index", index);
});
这将把索引设置为
0、1、2
等。如果您想从
0
以外的内容开始:

var offset = 1;
$('.section').each(function(index) {
  $(this).css("z-index", offset + index);
});

$('.section')。每个(函数(索引,el){$(el).css('z-index',索引+起始值);})
开始的_z-index _值
替换为要开始的值。对我来说效果很好。控制台中有错误吗?您有jquery吗?看看我的答案。啊,没关系,我看错了。。。工作得很好。