多语言展示
当前在线:1850今日阅读:86今日分享:14

layui三级菜单

使用了一些采用layui的框架,对于导航菜单,只能到二级,在这里,通过修改原框架js,达到能使用三级菜单的效果
工具/原料
1

开发web编辑器

2

原框架js,css,html

方法/步骤
2

二、在数据库中,根据菜单的type类型,进行区分,在示例中,按照1,2,3的方式来定义菜单级别,修改JS,直接上代码,类型为2的则为三级菜单的父节点。生成菜单的方法:template: [        '

  • ',        '',        '',        '{{item.name}}',        '',        '',        '
    ',        '
    ',        ' {{item.name}}',        '',        '',        '{{item.name}}',        '',        '',        '',        '
    ',        '
    ',        ' {{item.name}}',        '
  • '    ].join('')

    3

    三、根据模板中定义的html元素,进行处理点击的逻辑,直接上代码:$('#larry-nav-side').children('ul').find('li').each(function () {                var $this = $(this);                if ($this.find('dl').length > 0) {                    var $dd = $this.find('dd').each(function () {                    var $this = $(this);                    var flag = true;                    if($this.find('ol').length > 0){                    $(this).on('click', function () {                    if(flag){                    $(this).children().toggle();                    $(this).find('a').removeAttr('style');                    }                flag=true;                    });                    var $threeli =$this.children('ol').find('li').each(function(){                    $(this).on('click', function () {                    var $a = $(this).children('a');                    var href = $a.data('url');                    var icon = $a.children('i:first').data('icon');                    var title = $a.children('span').text();                    var data = {                    href: href,                    icon: icon,                    title: title                    }                    navtab.tabAdd(data);                    flag=false;                    });                    });                     }else{                    $(this).on('click', function () {                    var $a = $(this).children('a');                    var href = $a.data('url');                    var icon = $a.children('i:first').data('icon');                    var title = $a.children('span').text();                    var data = {                    href: href,                    icon: icon,                    title: title                    }                    navtab.tabAdd(data);                    });                    }                    });                                                    } else {                    $this.on('click', function () {                        var $a = $(this).children('a');                        var href = $a.data('url');                        var icon = $a.children('i:first').data('icon');                        var title = $a.children('span').text();                        var data = {                            href: href,                            icon: icon,                            title: title                        }                        navtab.tabAdd(data);                    });                }            });

    注意事项

    针对某些使用了layui的框架,未存在三级菜单的修改

    推荐信息