当前位置:首页 > Web开发 > 正文

JS获取contextPath的方法

2024-03-31 Web开发

function getContextPath() {

var pathName = document.location.pathname;
    var index = pathName.substr(1).indexOf("http://www.mamicode.com/");
    var result = pathName.substr(0,index+1);
    return result;

}

tips:

在一个使用layui.config的方法路径中写成‘../../static/...‘,

当不加项目名启动war包时,,显示正常,而加上项目名在测试环境下跑时就会报错

路径应该是’./static/...‘,表示从上往下寻找文件。

(开发环境跟测试环境还是有差别的,不能缺少测试环节)

JS获取contextPath的方法

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/40908.html