思路:根据访问的路径动态的设置菜单的折叠。前提是同一级菜单放大同一文件夹下面,根据文件夹的名字动态的设置菜单的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"); } }); } })
原文地址:https://www.cnblogs.com/qlqwjy/p/8313291.html
时间: 2024-11-07 00:17:12