gpt4 book ai didi

$(this).find (':nth-child(2)' 上的 jquery 选择器混合)

转载 作者:行者123 更新时间:2023-12-01 03:17:35 25 4
gpt4 key购买 nike

我对 jquery 和选择器有点困惑。

在此网站上http://pelloponisos.telesto.gr/我正在建立一个主菜单。我想要的只是使直接子菜单(主菜单中每个 li 的第二个子菜单)在鼠标悬停时显示并在鼠标移开时隐藏。

使菜单在鼠标悬停时工作的 jquery 代码是:

$("#access ul li").mouseover(function(){
$(this).find(':nth-child(2)').show();
}).mouseout(function(){
$(':nth-child(2)',this).hide();
});

但正如您所看到的,代码与每个第二个子菜单匹配,从而立即展开所有子菜单。

有人可以指出我错过了什么吗?

最佳答案

您可以尝试使用直接子选择器:

$(this).find('> :nth-child(2)').show();

或者:

$("#access ul li").hover(function(){
$('> :nth-child(2)', this).toggle();
});

关于$(this).find (':nth-child(2)' 上的 jquery 选择器混合),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13866940/

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