本文介绍了如何将“奇数"和“偶数"类添加到 div (Jquery)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 Jquery 向 div 添加奇数"和偶数"类?我有这个 html
<div class="item"></div><div class="item"></div><div class="item"></div><div class="item"></div>
我需要向div.item"添加奇数"和偶数"类才能获得此
<div class="item奇数"></div><div class="item even"></div><div class="item奇数"></div><div class="item even"></div>
解决方案
$('.carousel item:odd').addClass('odd');$('.carousel item:even').addClass('even');
How to add 'odd' and 'even' classes to divs using Jquery?I have this html
<div class="carousel" >
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
and I need to add 'odd' and 'even' classes to the 'div.item' to get this
<div class="carousel" >
<div class="item odd"></div>
<div class="item even"></div>
<div class="item odd"></div>
<div class="item even"></div>
</div>
解决方案
You can use :odd
and :even
selector
$('.carousel item:odd').addClass('odd');
$('.carousel item:even').addClass('even');
这篇关于如何将“奇数"和“偶数"类添加到 div (Jquery)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!