1

悬停父 UL 时如何选择菜单项 (LI)?

例子:

<ul class="topmenu">
    <li>item 1</li>
    <li>item 2</li>
    <li class="thisone">item 3
        <ul>
            <li>subMenu1</li>
            <li>subMenu2
                <ul>
                    <li>This should appear when Hover First Level Item3, would be like someone would be hovering subMenu2, but when actually hovered Item3</li>
                </ul>
            </li>
        <li>subMenu3</li>
        </ul>
    </li>
    <li>item 4</li>
</ul>

jQuery(像这样)

$document.ready(function(){
    $('.topmenu .thisone').hover(function(){
        $(this).closest('li:has('ul')).select();
    });
});

有人可以帮忙吗?谢谢!

4

2 回答 2

2

你的意思是像

$(document).ready(function(){
    $('.topmenu > li:has(ul)').hover(function(e){
        $(this).find('ul').toggle(e.type == 'mouseenter');
    });
});

演示:小提琴

于 2013-09-19T13:13:23.930 回答
0

尝试这样做:

$(document).ready(function(){
    $('.topmenu .thisone').mouseover(function(){
       $(this).closest('li:has("ul")').toggleClass('className');
    });
});
于 2013-09-19T13:16:02.883 回答