gpt4 book ai didi

jquery - 添加CSS到:last-child but only if it's not :odd

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

我有一个动态生成的 div 列表,并且我有这个脚本来制作交替背景颜色 - 为了 IE。

<style type="text/css">
.box { height:30px; width:100px; background-color:#fff; }
</style>

<script type="text/javascript">
$(document).ready(function () {
$(".box:odd").css("background-color", "#f1f1f1");
});
</script>

我的html:

<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
...

我想对 :last-child 应用特殊的 css 样式,但前提是 :last-child 不是 :odd - 意味着只有它具有白色背景。

我该怎么做?

最佳答案

 $(".box:last").not(':odd').css("background-color", "#f1f1f1"); 

关于jquery - 添加CSS到:last-child but only if it's not :odd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13006739/

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