首页 > 代码库 > js例子记载

js例子记载

1.获取项目路径的,不一定有用,仅作参考用:

技术分享
1 function getRootPath() {
2     var curWwwPath = window.document.location.href;            //"http://localhost:8080/springMVC/jsonTest.jsp"
3     var pathName = window.document.location.pathname;        // /springMVC/jsonTest.jsp
4     var pos = curWwwPath.indexOf(pathName);                    // 21
5     var localhostPath = curWwwPath.substring(0, pos);        //http://localhost:8080
6     var projectName = pathName.substring(0, pathName.substr(1).indexOf(‘/‘) + 1);    //   /springMVC
7 
8     return (localhostPath + projectName);    //http://localhost:8080/springMVC
9 }
View Code

 

js例子记载