带有不可点击链接的多级推送菜单问题

时间:2013-12-28 09:32:21

标签: jquery menu multi-level

我尝试实施http://multi-level-push-menu.make.rs/,但我遇到链接问题。

有问题的代码在这里:

<li><a href="http://www.google.com">Collections</a></li>
<li><a href="http://www.google.com">Credits</a></li>

完整代码:http://jsfiddle.net/AWJJ4/3/

为什么收藏积分不重定向外部网址?

1 个答案:

答案 0 :(得分:5)

preventItemClick选项默认设置为true。将其设置为false将解决您的问题。

<script>
$( '#menu' ).multilevelpushmenu({
    preventItemClick: false
});
</script>

但是,强烈建议使用如下所示的回调。

<script>
$( '#menu' ).multilevelpushmenu({
    onItemClick: function() {
        // First argument is original event object
        var event = arguments[0],
            // Second argument is menu level object containing clicked item (<div> element)
            $menuLevelHolder = arguments[1],
            // Third argument is clicked item (<li> element)
            $item = arguments[2],
            // Fourth argument is instance settings/options object
            options = arguments[3];

        // You can do some cool stuff here before
        // redirecting to href location
        // like logging the event or even
        // adding some parameters to href, etc...

        // Anchor href
        var itemHref = $item.find( 'a:first' ).attr( 'href' );
        // Redirecting the page
        location.href = itemHref;
    }
});
</script>

更新了小提琴,http://jsfiddle.net/AWJJ4/10/