当在Dropdown处悬停UL LI时,如何选择LI作为' hover'

时间:2013-09-19 13:07:45

标签: jquery css

如何在悬停父级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();
    });
});

有人可以提供帮助吗?谢谢!

2 个答案:

答案 0 :(得分:2)

你的意思是

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

演示:Fiddle

答案 1 :(得分:0)

尝试这样做:

$(document).ready(function(){
    $('.topmenu .thisone').mouseover(function(){
       $(this).closest('li:has("ul")').toggleClass('className');
    });
});