gpt4 book ai didi

jquery - 通过jquery每次迭代4次后添加一个类

转载 作者:行者123 更新时间:2023-12-01 08:10:25 25 4
gpt4 key购买 nike

我需要做的是在第 1 个第 5 个第 9 个第 13 个 div 等上添加一个类,但我编写的脚本是硬编码的,这对我来说效果很好,但问题是它仅将类添加到第 5 个,但我需要 1 、5、9 等等

  <div class="impresna-wrapp">
<div class="impresna ">
<p><img src="http://localhost/AON/wp-content/uploads/2012/12/impresna-img- 1.jpg" alt="impresna-img-1" width="203" height="101" class="alignnone size-full wp-image-46"></p>
<p><span class="emboss">EXTRA</span> | Ronaldo arremata capacete de Rubens Barrichello em leil�o de caridade em torneio de golf...</p>
<a href="#">+MAIS</a>
<br clear="all">
</div>
<div class="impresna ">
<p><img class="alignnone size-full wp-image-46" alt="impresna-img-1" src="http://localhost/AON/wp-content/uploads/2012/12/impresna-img-1.jpg" width="203" height="101"></p>
<p><span class="emboss">EXTRA</span> | Ronaldo arremata capacete de Rubens Barrichello em leil�o de caridade em torneio de golf...</p>
<a href="#">+MAIS</a>
<br clear="all">
</div>
<div class="impresna ">
<p><img class="alignnone size-full wp-image-46" alt="impresna-img-1" src="http://localhost/AON/wp-content/uploads/2012/12/impresna-img-1.jpg" width="203" height="101"></p>
<p><span class="emboss">EXTRA</span> | Ronaldo arremata capacete de Rubens Barrichello em leil�o de caridade em torneio de golf...</p>
<a href="#">+MAIS</a>
<br clear="all">
</div>
<div class="impresna ">
<p><img class="alignnone size-full wp-image-46" alt="impresna-img-1" src="http://localhost/AON/wp-content/uploads/2012/12/impresna-img-1.jpg" width="203" height="101"></p>
<p><span class="emboss">EXTRA</span> | Ronaldo arremata capacete de Rubens Barrichello em leil�o de caridade em torneio de golf...</p>
<a href="#">+MAIS</a>
<br clear="all">
</div>
<div class="impresna ">
<p><img class="alignnone size-full wp-image-46" alt="impresna-img-1" src="http://localhost/AON/wp-content/uploads/2012/12/impresna-img-1.jpg" width="203" height="101"></p>
<p><span class="emboss">EXTRA</span> | Ronaldo arremata capacete de Rubens Barrichello em leil�o de caridade em torneio de golf...</p>
<a href="#">+MAIS</a>
<br clear="all">
</div>
<div class="impresna ">
<p><img class="alignnone size-full wp-image-46" alt="impresna-img-1" src="http://localhost/AON/wp-content/uploads/2012/12/impresna-img-1.jpg" width="203" height="101"></p>
<p><span class="emboss">EXTRA</span> | Ronaldo arremata capacete de Rubens Barrichello em leil�o de caridade em torneio de golf...</p>
<a href="#">+MAIS</a>
<br clear="all">
</div>
<div class="impresna ">
<p><img class="alignnone size-full wp-image-46" alt="impresna-img-1" src="http://localhost/AON/wp-content/uploads/2012/12/impresna-img-1.jpg" width="203" height="101"></p>
<p><span class="emboss">EXTRA</span> | Ronaldo arremata capacete de Rubens Barrichello em leil�o de caridade em torneio de golf...</p>
<a href="#">+MAIS</a>
<br clear="all">
</div>


<div class="impresna zoom-img" id="zoom-img">
<p><img src="http://localhost/AON/wp-content/uploads/2012/12/impresna-zoom-img.jpg" alt="impresna-zoom-img" width="122" height="170" class="alignnone size-full wp-image-66"></p>
<span class="main"><span class="emboss">MARCA - SP</span> 20.09.12
<a href="#">+ZOOM</a></span>
<br clear="all">
</div>
<div class="impresna zoom-img" id="zoom-img">
<p><img src="http://localhost/AON/wp-content/uploads/2012/12/impresna-zoom-img.jpg" alt="impresna-zoom-img" width="122" height="170" class="alignnone size-full wp-image-66"></p>
<span class="main"><span class="emboss">MARCA - SP</span> 20.09.12
<a href="#">+ZOOM</a></span>
<br clear="all">
</div>

</div>

这是脚本:

           $('div.impresna-wrapp').find('div.impresna:nth-child(5)').each(function() {
$(this).addClass("alter-impresna");
});

最佳答案

您需要使用nth-child(4n+1)

<强> Live Demo

$('div.impresna-wrapp').find('div.impresna:nth-child(4n+1)').each(function() {
$(this).addClass("alter-impresna");
});

关于jquery - 通过jquery每次迭代4次后添加一个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14039642/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com