gpt4 book ai didi

javascript - 替换每第 n 个类名并借助 jQuery 替换它

转载 作者:太空宇宙 更新时间:2023-11-03 23:30:06 24 4
gpt4 key购买 nike

我想更换每第 6 个 div 类。

这是我当前的代码

<div class="disp">...</div>
<div class="disp">...</div>
<div class="disp">...</div>
<div class="disp">...</div>
<div class="disp">...</div>
<div class="disp">...</div> this should be change
<div class="disp">...</div>
<div class="disp">...</div>
<div class="disp">...</div>
<div class="disp">...</div>
<div class="disp">...</div>
<div class="disp">...</div> this should be change
<div class="disp">...</div>
<div class="disp">...</div>
<div class="disp">...</div>
<div class="disp">...</div>
<div class="disp">...</div>
<div class="disp">...</div> this should be change
<div class="disp">...</div>
<div class="disp">...</div>
<div class="disp">...</div>
<div class="disp">...</div>
<div class="disp">...</div>

它是无限的和未定义的计数,因为它在每个部分都有变化

最佳答案

你可以试试这个:

$( "div:nth-child(6n)" ).removeClass("disp");

或者

$( "div.disp:nth-child(6n)" ).removeClass("disp");

关于javascript - 替换每第 n 个类名并借助 jQuery 替换它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25640182/

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