--- title: 'Location: hash' slug: Web/API/Location/hash translation_of: Web/API/Location/hash ---
{{domxref("Location")}} 接口的 hash 属性返回一个 {{domxref("USVString")}},其中会包含URL标识中的 '#' 和 后面URL片段标识符。
这里 fragment 不会经过百分比编码(URL编码)。如果 URL 中没有 fragment,该属性会包含一个空字符串,""
string = object.hash; object.hash = string;
<a id="myAnchor" href="/en-US/docs/Location.href#Examples">Examples</a>
<script>
var anchor = document.getElementById("myAnchor");
console.log(anchor.hash); // 返回'#Examples'
</script>
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('HTML WHATWG', '#dom-location-hash', 'hash')}} | {{Spec2('HTML WHATWG')}} | Initial definition |
{{Compat("api.Location.hash")}}