<script type="text/javascript" src=“你所需要的js的网络地址"></script>
没个东西都有对应的地址,像网站,你打开自己的项目的首页通常是:http://localhost:8080/你自己的项目名/index.jsp。那么就有对应的js位置:http://localhost:8080/你自己的项目名/....
(你所需要的js的网络地址)就是去除js位置中:http://localhost:8080后的东西。
<script language="javascript">function Page_Path(level){ //level为1则跟目录 2则上层目录
var strUrl=window.location.href
var arrUrl=strUrl.split("/")
var strPage=arrUrl[arrUrl.length-level]
var filePath = location.href.substring(8, location.href.indexOf(strPage))
var r = /%20/g
filePath = filePath.replace(r," ")//查找所有的%20并替换为""}
return filePath
}
document.write(Page_Path(2))
</script>
Page_Path参数1为本目录,2为上级,3为上级的上级……
//假设你的路径为strstr="a.com/aaa/bbb/1.html"
str=str.replace(/\/[^\/]+\/[^\/]+$/,"/")