Location: hash
Location
接口的 hash
属性返回一个 USVString
,其中会包含URL标识中的 '#'
和 后面URL片段标识符。
这里 fragment 不会经过百分比编码(URL编码)。如果 URL 中没有 fragment,该属性会包含一个空字符串,""
Syntax
string = object.hash; object.hash = string;
Examples
<a id="myAnchor" href="/en-US/docs/Location.href#Examples">Examples</a>
<script>
var anchor = document.getElementById("myAnchor");
console.log(anchor.hash); // 返回'#Examples'
</script>
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard hash |
Living Standard | Initial definition |
Browser compatibility
BCD tables only load in the browser