例
返回URL的錨點部分。 假定當前的URL是http://www.example.com/test.htm#part2:
var x = location.hash;
x的結果將是:
#part2
更多“試一試”的例子。
定義和用法
哈希屬性設置或返回URL的錨部分,包括散列符號(#)。
注意:當這個屬性被用於設置錨點部分,不包括散列符號(#)。
瀏覽器支持
屬性 | |||||
---|---|---|---|---|---|
hash | 是 | 是 | 是 | 是 | 是 |
句法
返回hash屬性:
location.hash
設置hash屬性:
location.hash= anchorname
屬性值
Value | Type | Description |
---|---|---|
anchorname | String | Specifies the anchor part of a URL |
技術細節
返回值: | 一個字符串,代表URL的錨部分,包括散列符號(#) |
---|

更多示例
