-原始的悬停代码-

function bind_dropdown() {
    $('div#quick_nav div.search_dropdown').on('hover', function() {
        var thisid = $(this).attr('id').split('_');
        var this_action = thisid[1];
        var this_width = 950;
        var add_class = 'dropdown_full';

        if(this_action == 4) {
            this_width = 200;
            add_class = 'dropdown_small';
        }

        if($('div#quick_nav div#dropdown_'+escape(this_action)).is(':visible')) {
            $('div#quick_nav div#dropdown_'+escape(this_action)).addClass(add_class).slideUp(100);
        }
        else{
            $('div#quick_nav div.dropdown').hide();
            $('div#quick_nav div#dropdown_'+escape(this_action)).addClass(add_class).slideDown(100).width(this_width);
        }
        return false;
    });
}


---原始代码结尾---

我确实尝试过将鼠标悬停以单击。但是,它可以关闭菜单,您现在必须再次单击菜单图标。任何帮助将不胜感激。我希望能够单击以显示菜单,当鼠标移出菜单时,它将自动关闭。

先感谢您

Ĵ

最佳答案

使用下面的代码

function bind_dropdown() {
    $('div#quick_nav div.search_dropdown').on('click', function() {
        var thisid = $(this).attr('id').split('_');
        var this_action = thisid[1];
        var this_width = 950;
        var add_class = 'dropdown_full';

        if(this_action == 4) {
            this_width = 200;
            add_class = 'dropdown_small';
        }

        if($('div#quick_nav div#dropdown_'+escape(this_action)).is(':visible')) {
            $('div#quick_nav div#dropdown_'+escape(this_action)).addClass(add_class).slideUp(100);
        }
        return false;
    }).on("mouseleave", function() {
        var thisid = $(this).attr('id').split('_');
        var this_action = thisid[1];
        var this_width = 950;
        var add_class = 'dropdown_full';

        if(this_action == 4) {
            this_width = 200;
            add_class = 'dropdown_small';
        }
        $('div#quick_nav div.dropdown').hide();
        $('div#quick_nav div#dropdown_'+escape(this_action)).addClass(add_class).slideDown(100).width(this_width);
    });
}

10-05 21:01
查看更多