<script>
a="http://www.sohu.com/news/test.asp";
a=a.substr(a.indexOf("//")+"//".length)
a=a.substr(0,a.indexOf("/"))
alert(a)
</script>

解决方案 »

  1.   

    <script>
    a="http://www.sohu.com/news/test.asp";
    alert(GetServer(a))function GetServer(url)
    {
    url=url.substr(url.indexOf("//")+"//".length)
    url=url.substr(0,url.indexOf("/"))
    return url
    }
    </script>
      

  2.   

    <script>
    var url="http://www.sohu.com/abc/bcd/234.htm",url_str;
    //url=this.location.toString();
    //alert(url);
      url_str = url.split("/");
    alert(url_str[2]);
    </script>有没有更好的办法?
      

  3.   

    a = "http://www.sohu.com/news/test.asp";
    s = a.replace(/.*\/{2}(.+?)\/.*/, '$1'); 
    alert(s);