1

我需要做的是在 1st 5th 9th 13th 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");
            });
4

1 回答 1

3

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

现场演示

$('div.impresna-wrapp').find('div.impresna:nth-child(4n+1)').each(function() {
           $(this).addClass("alter-impresna");
});
于 2012-12-26T11:01:21.207 回答