您现在的位置: 万盛学电脑网 >> 程序编程 >> 脚本专题 >> javascript >> 正文

在js文件中如何获取basePath处理js路径问题

作者:佚名    责任编辑:admin    更新时间:2022-06-22

js路径的问题有时候不好处理,在jsp中,我们可以用el表达式直接获取basePath,但是在单独js文件中不能用el表达式,又不想在jsp中单独的写个变量,可以用以下方法:

复制代码 代码如下:


var location = (window.location+'').split('/');
var basePath = location[0]+'//'+location[2]+'/'+location[3];
var url = basePath + '/js/xxx.js';