<script language="javascript">
str="http://localhost:8080/a/b/c/d/e/test.jsp"
var a = str.match(/^(http:\/\/.[^\/]*)(.*?)([^\/]*)$/);
alert(a[1])
alert(a[2])
alert(a[3])
</script>

解决方案 »

  1.   

    考虑到ie5
    <script language="javascript">
    str="http://localhost:8080/a/b/c/d/e/test.jsp"
    var a = str.match(/^(http:\/\/.[^\/]*)(.*[\/])([^\/]*)$/);
    alert(a[1])
    alert(a[2])
    alert(a[3])
    </script>
      

  2.   

    <script language=javascript>
    function get(str)  //从链接地址里提取出本文档名
    {
      alert(str.match(/\/([^\?/]*)(\?|$)/)[1])
    }
    get(location.href)
    get("http://www.xxxx.com/xxx/xxx.htm")
    get("http://www.xxxx.com/xxx/xxx.htm?text1=abcde&text2=fghij")
    </script>