javascript jQuery 不同網頁引用時需要的根目錄
GOOGLE的網友寫法
在不同路徑引用同一支JQ時,路徑會有問題。由其在AJAX的時候常會用到。
JS取得根目錄的function:
//取得根目錄
function getRootPath(){
var strFullPath=window.document.location.href;
var strPath=window.document.location.pathname;
var pos=strFullPath.indexOf(strPath);
var prePath=strFullPath.substring(0,pos);
var postPath=strPath.substring(0,strPath.substr(1).indexOf('/')+1);
return(prePath+postPath);
}
alert(getRootPath());//測試
學習地址
http://www.girlcoding.com/2011/08/javascript-websit-url/