From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/location/hash/index.html | 47 ++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 files/zh-cn/web/api/location/hash/index.html (limited to 'files/zh-cn/web/api/location/hash') diff --git a/files/zh-cn/web/api/location/hash/index.html b/files/zh-cn/web/api/location/hash/index.html new file mode 100644 index 0000000000..0a0d45e220 --- /dev/null +++ b/files/zh-cn/web/api/location/hash/index.html @@ -0,0 +1,47 @@ +--- +title: 'Location: hash' +slug: Web/API/Location/hash +translation_of: Web/API/Location/hash +--- +
{{ APIRef("Location") }}
+ +

{{domxref("Location")}} 接口的 hash 属性返回一个 {{domxref("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

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', '#dom-location-hash', 'hash')}}{{Spec2('HTML WHATWG')}}Initial definition
+ +

Browser compatibility

+ + + +

{{Compat("api.Location.hash")}}

-- cgit v1.2.3-54-g00ecf