<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">
var path = location.href;
var pathone = path.slice(path.lastIndexOf("/")+1) ;
alert(pathone);
</script>
<body>
</body>
</html>

解决方案 »

  1.   

    alert(this.location.pathname.match(/(?!.*\/)[^\.]*/))
      

  2.   

    path.slice(path.lastIndexOf("/")+1).split(".")[0] ;
      

  3.   

    <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>
      

  4.   

    yyy431706(观兰) 如果是 index.xxx?xxx=xxxx&aaa=aaaa 这样怎么办
      

  5.   

    alert(this.location.pathname.match(/(?!.*[\/\\])[^\.]*/));//取得index
    alert(this.location.pathname.match(/(?!.*[\/\\])[^\?]*/));//取得index.asp为了适应各种情况还是用这个PS:见到了一个钻石级的高手 羡慕中......
      

  6.   


    <script language=javascript>
    re=/(\/|\\)(([^\\\/](?!($|\?)))+?(.(?=($|\?))))/
    re.test(this.location.pathname)
    alert(RegExp.$2);
    </script>
      

  7.   

    大梅的程序怎么不好了?
    gzdiablo() 你的这段正则有些问题,很多web程序的地址是镜象的,而不是直接拿文件名,所以你的程序并不是通用所有情况,比如说
    http://www.csdn.net/testServlet?a=1&b=2
      

  8.   

    哦 不好意思 是我忽略了这点 改成这样就没问题了alert(this.location.pathname.match(/(?!.*[\/\\])[^\.\?]*/));//取得index
    alert(this.location.pathname.match(/(?!.*[\/\\])[^\?]*/));//取得index.asp
      

  9.   

    钻石级的高手是大家对他的能力的评价我不敢质疑
    但再厉害也有弱的项目 正所谓三人行必有我师
    hbhbhbhbhb1021(天外水火(我要多努力))似乎太偏激了
    大家互相学习嘛 指出对方的错误可以指导对方学习新的知识
    你刚才指出的错误就对我帮助很大 呵呵~~
      

  10.   

    上面那段代码是我几年前写的,随手COPY过来了,TO gzdiablo() 我不是很喜欢使用 ?! ,并不是我不会用,只是这东西在IE5.0里通不过,所以我写正则的时候多半是一些老土的代码:<script language=javascript>
    function get(str)  //从链接地址里提取出本文档名
    {
      alert(str.match(/\/([^\.\?/]*)(\.[^\?/]+)?(\?|$)/)[1])
    }
    get(location.href)
    get("http://www.xxxx.com/xxx/xx1.htm")
    get("http://www.xxxx.com/xxx/xx2.htm?text1=abcde&text2=fghij")
    get("http://www.xxxx.com/xxx/xx3?text1=abcde&text2=fghij")
    </script>
      

  11.   

    没有问题的说支持meizz
    比如:http://www.xxxx.com/xxx/xxx.htm
    /\/([^\?\/]+)(\?|$)/
    是匹配开头为/但是中间不包含/并且结尾为$或者为?
    满足这一条件的只有。。/xxx.htm
    然后捕获xx.htm
      

  12.   

    TO gzdiablo() 别在意,我只是好奇,想看看那段程序的不好之处啦。
      

  13.   

    哦突然想到还有种可能性index.asp#xxxalert(this.location.pathname.match(/(?!.*[\/\\])[^\.\?\#]*/));//取得index
    alert(this.location.pathname.match(/(?!.*[\/\\])[^\?\#]*/));//取得index.asp