zoukankan      html  css  js  c++  java
  • 项目中菜单折叠问题

    思路:根据访问的路径动态的设置菜单的折叠。前提是同一级菜单放大同一文件夹下面,根据文件夹的名字动态的设置菜单的class属性。

    例如:

      我的一个url:

    http://localhost/Exam/view/outDepart/outdepartEmpManage.jsp

      location.pathname获取到除去ip与端口的地址  /Exam/view/outDepart/outdepartEmpManage.jsp

    $(function() {
        var u = location.pathname;
    
        u = u.substring(11, u.length);
        var fir = u.indexOf("/");
        var filename = u.substring(0, fir)
        // 删除class
        $(".mtree-active").removeClass("mtree-active mtree-open");
        if (filename == "innerDepart") {
            // 检索内部的url
            $(".mtree a").each(
                    function(i) {
                        var url = $(this).prop("href");
                        if (url.toString().indexOf(filename) > 0) {
                            $(this).parents("[class^='mtree-level']").css({
                                display : "block",
                                height : "auto"
                            });
                            $(this).parents(".mtree-node").removeClass("mtree-closed");
                            $(this).parents(".mtree-node").addClass("mtree-open");
                            $(this).parents(".mtree-level-1").children(
                                    ".mtree-open").addClass("mtree-active");
                        }
    
                    });
        } else if (filename == "outDepart") {
            // 检索内部的url
            $(".mtree a").each(
                    function(i) {
                        var url = $(this).prop("href");
                        if (url.toString().indexOf(filename) > 0) {
                            $(this).parents("[class^='mtree-level']").css({
                                display : "block",
                                height : "auto"
                            });
                            $(this).parents(".mtree-node").removeClass("mtree-closed");
                            $(this).parents(".mtree-node").addClass("mtree-open");
                            $(this).parents(".mtree-level-1").children(
                                    ".mtree-open").addClass("mtree-active");
                        }
    
                    });
        }else{
            // 检索内部的url
            $(".mtree a").each(
                    function(i) {
                        var url = $(this).prop("href");
                        if (url.toString().indexOf(filename) > 0) {
                            $(this).parents("[class^='mtree-level']").css({
                                display : "block",
                                height : "auto"
                            });
                            $(this).parents(".mtree-node").removeClass("mtree-closed");
                            $(this).parents(".mtree-node").addClass("mtree-open mtree-active");
                        }
    
                    });
        }
    })
  • 相关阅读:
    IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass(); 时,报COMException
    Asp.net MVC 发布到IIS6
    String.Net “System.TypeInitializationException”类型的未经处理的异常在 Spring.NetDemo.exe 中发生
    C#通过外部别名,解决DLL冲突问题
    c# DPI SCale
    c# 技巧
    正则笔记
    php & c# DES
    WPF页面切换
    C# 委托与事件
  • 原文地址:https://www.cnblogs.com/qlqwjy/p/8313291.html
Copyright © 2011-2022 走看看