<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>
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 .
说的也不完全,应该是"/"后面.如果有"?"的话,"?"前面的那一部分,
比如说你用GET方法提交一个表单时的location.href为:http://www.xxxx.com/xxx/xxx.htm?text1=abcde&text2=fghij
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>
====================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 .