//获取根目录(域名+工程名) var getBasePath = function () { var curWwwPath = window.document.location.href; console.info(curWwwPath); var pathName = window.document.location.pathname; console.info(pathName); var pos = curWwwPath.indexOf(pathName); console.info(pos); var localhostPaht = curWwwPath.substring(0, pos); console.info(localhostPaht); var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1); console.info(projectName); return (localhostPaht + projectName); }