gpt4 book ai didi

jQuery:遍历问题

转载 作者:行者123 更新时间:2023-12-01 01:58:00 26 4
gpt4 key购买 nike

我试图找到一些关于 jQuery 遍历的像样的文档,但没有找到像样的资源,任何建议将不胜感激。

我正在尝试为菜单创建一个简单的动画。

我有一个简单的菜单:

<ul class='contentNav'>
<li><a href='#'>One</a>
<li><a href='#'>Two</a>
<li><a href='#'>Three</a>
<li><a href='#'>Four</a>
</ul>

还有一个简单的 jquery 函数来更改标签的背景颜色:

$(document).ready(function(){

$(".contentNav a").hoverIntent(
function(over) {
$(this).animate({backgroundColor: "#844"}, "fast");
$(this).parent().find("li a").animate({backgroundColor: "#090"}, "fast");
},
function(out) {
$(this).animate({backgroundColor: "#000"}, "fast");
$(this).parent().find("li a").animate({backgroundColor: "#000"}, "fast");
});
});

问题在于以下几行:

$(this).parent().find("li a").animate({backgroundColor: "#090"}, "fast"); 
$(this).parent().find("li a").animate({backgroundColor: "#000"}, "fast");

我正在尝试选择当前未悬停的所有链接标记项并设置其背景颜色。我该怎么做呢。

谢谢。

<小时/>

更新

<小时/>

我采纳了所有建议并提出了以下代码:

$(this).parent().parent().find("a").not(this).animate({backgroundcolor: "#555"}, 100)

最佳答案

您的线路缺少额外的父线路:

$(this).parent().parent().find("li a").animate({backgroundColor: "#090"}, "fast"); 
$(this).parent().parent().find("li a").animate({backgroundColor: "#000"}, "fast");

由于您的初始选择器位于“a”标签上,因此如果您想使用 find("li a") 选择器,您需要先转到“li”标签,然后再转到包含的 div。

关于jQuery:遍历问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1424147/

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