图奈娱乐
您的当前位置:首页在js文件中如何获取basePath处理js路径问题_javascript技巧

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

来源:图奈娱乐


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';
显示全文