<input type=button value=ok onclick="alert(self.location.href)">

解决方案 »

  1.   

    var fileName = top.location.href;
      

  2.   

    location.href只能得到http://www.csdn.net/index.htm一个地址,要得到文件名还要用split()截取"/"的最后一组,就这么简单
      

  3.   

    dugucan()alert("独孤残")
    说的也不完全,应该是"/"后面.如果有"?"的话,"?"前面的那一部分,
    比如说你用GET方法提交一个表单时的location.href为:http://www.xxxx.com/xxx/xxx.htm?text1=abcde&text2=fghij
      

  4.   

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

  5.   

    Property Description 
    ====================hash 
    ----
    Sets or retrieves the subsection of the href property that follows the number sign (#). host 
    ----
    Sets or retrieves the hostname and port number of the location or URL. hostname 
    --------
    Sets or retrieves the host name part of the location or URL.  href 
    ----
    Sets or retrieves the entire URL as a string.  pathname 
    --------
    Sets or retrieves the file name or path specified by the --object.  port 
    ----
    Sets or retrieves the port number associated with a URL. protocol 
    --------
    Sets or retrieves the protocol portion of a URL.  search 
    ------
    Sets or retrieves the substring of the href property that follows the question .