我的站点根目录是http://.../llds/
我在其下的子目录..../cx,中要取得根目录路径,如何实现,要一个通用的方法,有的子目录可能是..../aa/bb更深的形式。我的根目录名http://.../llds/不是固定的,在正式用的时候可能改的.用javascript
我在其下的子目录..../cx,中要取得根目录路径,如何实现,要一个通用的方法,有的子目录可能是..../aa/bb更深的形式。我的根目录名http://.../llds/不是固定的,在正式用的时候可能改的.用javascript
var path="";
if(str.indexOf("http://")!=-1){
s=str.substring(str.indexOf("http://")+7,str.length)
s=s.split("/")
}
else{
s=str.split("健")
s=s[1].split("/")
}
//alert(s);
for(i=0;i<s.length-2;i++) path+="../"
return path;
}
根据你的需求可以适当的对目录进行调整。
在asp.net 可以用~/就取得了根目录
在javascript中能不能有一个通用的方法,根目录我可能是http://.../,或http://.../llds/
也可能更长,如何办
在asp.net 可以用~/就取得了根目录
在javascript中我用/,只能取得http://../目录,不能取得http://.../llds目录
在asp.net 可以用~/正常
在javascript中我用/,取得的是http://../目录,不是http://.../llds目录
等于说用/取得的是主站点的目录不是子站点的目录
re = /http:\/\/[^\/]*\//i;
alert(str.match(re));
re = /http:\/\/[^\/]*\//i;
alert(str.match(re));
yourpath = "llds";
re = new RegExp("http:\/\/.*?\/"+yourpath+"\/","i")
//str = "http://ashd/kfjhs/adfkh/llds/kjsadfhksadfh/asdjkfshagdfjsdf";
str = location.href;
alert(str.match(re));
</script>
http://xxx.xxx.xxx/
你要取得第一层子目录路径吧?