Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试做类似financial.yahoo.com 的菜单的事情,它会阻止它在活动菜单项处下拉。我已经应用 jQuery 添加addclass()到添加.active类,但现在我只想在活动类中停止下拉。
addclass()
.active
我在哪里尝试过这段代码但不起作用
$('#menu > ul > li > a.active').parent('div').hide();
使用最接近()而不是parent(),因为div它不是a. 最接近的将通过测试元素本身并遍历其在 DOM 树中的祖先来查找与选择器匹配的第一个元素
div
a
$('#menu > ul > li > a.active').closest('div').hide();
绑定到.mouseleave()事件。如同
.mouseleave()
$('.main_menu_container').mouseleave( function () { $(this).children('.submenu').hide(); });