我的站点根目录是http://.../llds/
我在其下的子目录..../cx,中要取得根目录路径,如何实现,要一个通用的方法,有的子目录可能是..../aa/bb更深的形式。我的根目录名http://.../llds/不是固定的,在正式用的时候可能改的.用javascript

解决方案 »

  1.   

    function relapath(str){
    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;
    }
    根据你的需求可以适当的对目录进行调整。
      

  2.   

    s=str.split("健")是什么
    在asp.net 可以用~/就取得了根目录
    在javascript中能不能有一个通用的方法,根目录我可能是http://.../,或http://.../llds/
    也可能更长,如何办
      

  3.   

    可是我不知道我的起始目录,因办我是要上传的
    在asp.net 可以用~/就取得了根目录
    在javascript中我用/,只能取得http://../目录,不能取得http://.../llds目录
      

  4.   

    我的站点根目录是http://.../llds/
    在asp.net 可以用~/正常
    在javascript中我用/,取得的是http://../目录,不是http://.../llds目录
    等于说用/取得的是主站点的目录不是子站点的目录
      

  5.   

    str = "http://............";
    re = /http:\/\/[^\/]*\//i;
    alert(str.match(re));
      

  6.   

    str = location.href;
    re = /http:\/\/[^\/]*\//i;
    alert(str.match(re));
      

  7.   

    <script language="javascript">
    yourpath = "llds";
    re = new RegExp("http:\/\/.*?\/"+yourpath+"\/","i")
    //str = "http://ashd/kfjhs/adfkh/llds/kjsadfhksadfh/asdjkfshagdfjsdf";
    str = location.href;
    alert(str.match(re));
    </script>
      

  8.   

    根目录不是
    http://xxx.xxx.xxx/
    你要取得第一层子目录路径吧?
      

  9.   

    http://www.cnblogs.com/eastday/archive/2010/01/29/1659297.html
      

  10.   

    呵呵就这样server.mappath("文件名")