Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery菜单_Jquery_Html - Fatal编程技术网

jQuery菜单

jQuery菜单,jquery,html,Jquery,Html,我正在使用以下jQuery菜单脚本: (function($) { $.fn.blowfish = function() { // hide original ul dom tree $(this).hide(); // create container from top-level li tags var top = $(this).children('li'); var container = $('<div/>').addCl

我正在使用以下jQuery菜单脚本:

(function($) {
    $.fn.blowfish = function() {

    // hide original ul dom tree
    $(this).hide();

    // create container from top-level li tags
    var top = $(this).children('li');
    var container = $('<div/>').addClass('bfcontainer').attr('id', 'cv' + Math.floor(Math.random()*10e10)).insertAfter(this);
    var topdiv = $('<div class="top"></div>').appendTo(container);

    // check if IE and set fixed width for first column
    if($.browser.msie) {
        $('.top').width('200px');
    }

    $.each(top, function(i, item) {
        var topitem = $(':eq(0)', item).clone().data('sub', $(item).children('ul')).appendTo(topdiv);

        if($(topitem).data('sub').length) {
            $(topitem).addClass('hasChildMenu');

            if($.browser.safari) {
                $(topitem).css({'margin-right' : '15px'});
            }
        }
    });

    // event handlers
    $('a', container).live('click', function() {
        var container = $(this).parents('.bfcontainer');

        // click handler
        var level = $('div', container).index($(this).parents('div'));

        // remove blocks to the right in the tree, and 'deactivate' other links within the same level
        $('div:gt('+level+')', container).remove();
        $('div:eq('+level+') a', container).removeClass('active').removeClass('inpath');
        $('.active', container).addClass('inpath');
        $(this).addClass('active');

        if($(this).data('sub').children('li').length) {
            // add submenu if container has children
            submenu(container, this);
        }
        else {
            // show title or link if container has no children
            var title = $('<a/>').attr({href : $(this).attr('href')}).text($(this).attr('title') ? $(this).attr('title') : $(this).text());
            var featurebox = $('<div/>').html(title).addClass('feature').appendTo(container);

            // set width
            var remainingspace = 0;

            $.each($(container).children('div').slice(0, -1), function(i, item) {
                remainingspace += $(item).width();
            });

            var fillwidth = $(container).width() - remainingspace;

            $(featurebox).css({'top': 0, 'left' : remainingspace}).width(fillwidth).show('slow');
        }

        return false;
    });
};

// create submenus
function submenu(container, item) {
    var leftPos = 0;

    $.each($(container).children('div'), function(i, mydiv) {
        leftPos += $(mydiv).width();
    });

    var submenu = $('<div/>').css({'top' : 0, 'left' : leftPos}).appendTo(container).fadeIn();

    // check if IE and set fixed width for submenu column
    if($.browser.msie) {
        $(submenu).width('200px');
    }

    var subitems = $(item).data('sub').children('li');

    $.each(subitems, function(i, subitem) {
        var subsubitem = $(':eq(0)', subitem).clone().data('sub', $(subitem).children('ul')).appendTo(submenu);

        if($(subsubitem).data('sub').length) {
            $(subsubitem).addClass('hasChildMenu');

            if($.browser.safari) {
                $(subsubitem).css({'margin-right' : '15px' });
            }
        }
    });
}  
})(jQuery);
(函数($){
$.fn.blowfish=函数(){
//隐藏原始ul-dom树
$(this.hide();
//从顶级li标记创建容器
var top=$(this.children('li');
var container=$('').addClass('bfcontainer').attr('id','cv'+Math.floor(Math.random()*10e10)).insertAfter(this);
var topdiv=$('').appendTo(容器);
//检查IE是否正确,并为第一列设置固定宽度
如果($.browser.msie){
$('.top').width('200px');
}
$。每个(顶部,功能(i,项目){
var topitem=$(':eq(0'),item.clone().data('sub',$(item.children('ul')).appendTo(topdiv);
if($(topitem).data('sub').length){
$(topitem).addClass('hasChildMenu');
if($.browser.safari){
$(topitem).css({'margin-right':'15px'});
}
}
});
//事件处理程序
$('a',container).live('click',function()){
var container=$(this.parents('.bfcontainer');
//单击处理程序
var level=$('div',container.index($(this.parents('div'));
//删除树中右侧的块,并“停用”同一级别内的其他链接
$('div:gt('+level+'),container.remove();
$('div:eq('+level+')a',container.removeClass('active').removeClass('inpath');
$('.active',container.addClass('inpath');
$(this.addClass('active');
if($(this).data('sub').children('li').length){
//如果容器有子菜单,则添加子菜单
子菜单(容器,此);
}
否则{
//如果容器没有子容器,则显示标题或链接
变量标题=$('
  • jQuery脚本为每个子菜单(如Mac OS X finder)添加了一个新列,我想对其进行修改,以便在没有更多子菜单的情况下,它实际上会获得链接的href属性,其行为与普通菜单类似(我使用AJAX将内容加载到另一个div中,如果您单击一个没有子项的项,那么我不能在脚本本身中使用window.location,而是必须在特定情况下禁用return false。我如何做到这一点

    您可以在此处查看工作示例:


    非常感谢。

    好的,我来回答我自己的问题:D

    以下是更新JS:

    (function($) {
        $.fn.blowfish = function() {
    
        // hide original ul dom tree
        $(this).hide();
    
        // create container from top-level li tags
        var top = $(this).children('li');
        var container = $('<div/>').addClass('bfcontainer').attr('id', 'cv' + Math.floor(Math.random()*10e10)).insertAfter(this);
        var topdiv = $('<div class="top"></div>').appendTo(container);
    
        // check if IE and set fixed width for first column
        if($.browser.msie) {
            $('.top').width('200px');
        }
    
        $.each(top, function(i, item) {
            var topitem = $(':eq(0)', item).clone().data('sub', $(item).children('ul')).appendTo(topdiv);
    
            if($(topitem).data('sub').length) {
                $(topitem).addClass('hasChildMenu');
    
                if($.browser.safari) {
                    $(topitem).css({'margin-right' : '15px'});
                }
            }
        });
    
        // event handlers
        $('a', container).live('click', function() {
            var container = $(this).parents('.bfcontainer');
    
            // click handler
            var level = $('div', container).index($(this).parents('div'));
    
            // remove blocks to the right in the tree, and 'deactivate' other links within the same level
            $('div:gt('+level+')', container).remove();
            $('div:eq('+level+') a', container).removeClass('active').removeClass('inpath');
            $('.active', container).addClass('inpath');
            $(this).addClass('active');
    
            if($(this).data('sub').children('li').length) {
                // add submenu if container has children
                submenu(container, this);
    
                return false;
            }
            else {
                // show title or link if container has no children
                /*
    var title = $('<a/>').attr({href : $(this).attr('href')}).text($(this).attr('title') ? $(this).attr('title') : $(this).text());
                var featurebox = $('<div/>').html(title).addClass('feature').appendTo(container);
    
                // set width
                var remainingspace = 0;
    
                $.each($(container).children('div').slice(0, -1), function(i, item) {
                    remainingspace += $(item).width();
                });
    
                var fillwidth = $(container).width() - remainingspace;
    
                $(featurebox).css({'top': 0, 'left' : remainingspace}).width(fillwidth).show('slow');
    */
                /* window.location($(this).attr('href')); */
            }
        });
    };
    
    // create submenus
    function submenu(container, item) {
        var leftPos = 0;
    
        $.each($(container).children('div'), function(i, mydiv) {
            leftPos += $(mydiv).width();
        });
    
        var submenu = $('<div/>').css({'top' : 0, 'left' : leftPos}).appendTo(container).fadeIn();
    
        // check if IE and set fixed width for submenu column
        if($.browser.msie) {
            $(submenu).width('200px');
        }
    
        var subitems = $(item).data('sub').children('li');
    
        $.each(subitems, function(i, subitem) {
            var subsubitem = $(':eq(0)', subitem).clone().data('sub', $(subitem).children('ul')).appendTo(submenu);
    
            if($(subsubitem).data('sub').length) {
                $(subsubitem).addClass('hasChildMenu');
    
                if($.browser.safari) {
                    $(subsubitem).css({'margin-right' : '15px' });
                }
            }
        });
    }  
    })(jQuery);
    
    (函数($){
    $.fn.blowfish=函数(){
    //隐藏原始ul-dom树
    $(this.hide();
    //从顶级li标记创建容器
    var top=$(this.children('li');
    var container=$('').addClass('bfcontainer').attr('id','cv'+Math.floor(Math.random()*10e10)).insertAfter(this);
    var topdiv=$('').appendTo(容器);
    //检查IE是否正确,并为第一列设置固定宽度
    如果($.browser.msie){
    $('.top').width('200px');
    }
    $。每个(顶部,功能(i,项目){
    var topitem=$(':eq(0'),item.clone().data('sub',$(item.children('ul')).appendTo(topdiv);
    if($(topitem).data('sub').length){
    $(topitem).addClass('hasChildMenu');
    if($.browser.safari){
    $(topitem).css({'margin-right':'15px'});
    }
    }
    });
    //事件处理程序
    $('a',container).live('click',function()){
    var container=$(this.parents('.bfcontainer');
    //单击处理程序
    var level=$('div',container.index($(this.parents('div'));
    //删除树中右侧的块,并“停用”同一级别内的其他链接
    $('div:gt('+level+'),container.remove();
    $('div:eq('+level+')a',container.removeClass('active').removeClass('inpath');
    $('.active',container.addClass('inpath');
    $(this.addClass('active');
    if($(this).data('sub').children('li').length){
    //如果容器有子菜单,则添加子菜单
    子菜单(容器,此);
    返回false;
    }
    否则{
    //如果容器没有子容器,则显示标题或链接
    /*
    var title=$('').attr({href:$(this.attr('href')}).text($(this.attr('title')?$(this.attr('title'):$(this.text());
    var featurebox=$('').html(title).addClass('feature').appendTo(container);
    //设定宽度
    var剩余空间=0;
    $.each($(容器).children('div').slice(0,-1),function(i,item){
    剩余空间+=$(项).width();
    });
    var fillwidth=$(container).width()-remaingspace;
    $(featurebox).css({'top':0,'left':remainingspace}).width(fillwidth.show('slow');
    */
    /*window.location($(this.attr('href'))*/
    }
    });
    };
    //创建子菜单
    功能子菜单(容器、项目){
    var-leftPos=0;
    $.each($(容器).children('div'),function(i,mydiv){
    leftPos+=$(mydiv).width();
    });
    var子菜单=$('').css({'top':0,'left':leftPos}).appendTo(container.fadeIn();
    //检查IE是否正确,并为子菜单列设置固定宽度
    如果($.browser.msie){
    $(子菜单).width('200px');
    }
    var subitems=$(item).data('sub').children('li');
    $。每个(子项,功能(i,子项){
    var subsubitem=$(':eq(0'),子项).clone().data('sub',$(子项).children('ul')).appendTo(子菜单);
    if($(子项).data('sub').length){
    $(subsubsubitem.addClass('hasChildMenu');
    if($.browser.safari){
    $(subsubsubitem.css({'margin-right':'15px');
    }
    }
    });
    }  
    })(jQuery);
    
    干杯, 马克斯

    (function($) {
        $.fn.blowfish = function() {
    
        // hide original ul dom tree
        $(this).hide();
    
        // create container from top-level li tags
        var top = $(this).children('li');
        var container = $('<div/>').addClass('bfcontainer').attr('id', 'cv' + Math.floor(Math.random()*10e10)).insertAfter(this);
        var topdiv = $('<div class="top"></div>').appendTo(container);
    
        // check if IE and set fixed width for first column
        if($.browser.msie) {
            $('.top').width('200px');
        }
    
        $.each(top, function(i, item) {
            var topitem = $(':eq(0)', item).clone().data('sub', $(item).children('ul')).appendTo(topdiv);
    
            if($(topitem).data('sub').length) {
                $(topitem).addClass('hasChildMenu');
    
                if($.browser.safari) {
                    $(topitem).css({'margin-right' : '15px'});
                }
            }
        });
    
        // event handlers
        $('a', container).live('click', function() {
            var container = $(this).parents('.bfcontainer');
    
            // click handler
            var level = $('div', container).index($(this).parents('div'));
    
            // remove blocks to the right in the tree, and 'deactivate' other links within the same level
            $('div:gt('+level+')', container).remove();
            $('div:eq('+level+') a', container).removeClass('active').removeClass('inpath');
            $('.active', container).addClass('inpath');
            $(this).addClass('active');
    
            if($(this).data('sub').children('li').length) {
                // add submenu if container has children
                submenu(container, this);
    
                return false;
            }
            else {
                // show title or link if container has no children
                /*
    var title = $('<a/>').attr({href : $(this).attr('href')}).text($(this).attr('title') ? $(this).attr('title') : $(this).text());
                var featurebox = $('<div/>').html(title).addClass('feature').appendTo(container);
    
                // set width
                var remainingspace = 0;
    
                $.each($(container).children('div').slice(0, -1), function(i, item) {
                    remainingspace += $(item).width();
                });
    
                var fillwidth = $(container).width() - remainingspace;
    
                $(featurebox).css({'top': 0, 'left' : remainingspace}).width(fillwidth).show('slow');
    */
                /* window.location($(this).attr('href')); */
            }
        });
    };
    
    // create submenus
    function submenu(container, item) {
        var leftPos = 0;
    
        $.each($(container).children('div'), function(i, mydiv) {
            leftPos += $(mydiv).width();
        });
    
        var submenu = $('<div/>').css({'top' : 0, 'left' : leftPos}).appendTo(container).fadeIn();
    
        // check if IE and set fixed width for submenu column
        if($.browser.msie) {
            $(submenu).width('200px');
        }
    
        var subitems = $(item).data('sub').children('li');
    
        $.each(subitems, function(i, subitem) {
            var subsubitem = $(':eq(0)', subitem).clone().data('sub', $(subitem).children('ul')).appendTo(submenu);
    
            if($(subsubitem).data('sub').length) {
                $(subsubitem).addClass('hasChildMenu');
    
                if($.browser.safari) {
                    $(subsubitem).css({'margin-right' : '15px' });
                }
            }
        });
    }  
    })(jQuery);