blob: c6f2f286aa400564eff753e5c47341210b4191e2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
---
title: 'Location: hash'
slug: Web/API/Location/hash
translation_of: Web/API/Location/hash
---
<div>{{ APIRef("Location") }}</div>
<p><span class="seoSummary">{{domxref("Location")}} 接口的 <strong><code>hash</code></strong> 属性返回一个 {{domxref("USVString")}},其中会包含URL标识中的 <code>'#'</code> 和 后面URL片段标识符。</span></p>
<p>这里 fragment 不会经过<a href="/en-US/docs/Glossary/percent-encoding">百分比编码</a>(URL编码)。如果 URL 中没有 fragment,该属性会包含一个空字符串,<code>""</code></p>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox notranslate"><em>string</em> = <em>object</em>.hash;
<em>object</em>.hash = <em>string</em>;
</pre>
<h2 id="Examples">Examples</h2>
<pre class="brush: html notranslate"><a id="myAnchor" href="/en-US/docs/Location.href#Examples">Examples</a>
<script>
var anchor = document.getElementById("myAnchor");
console.log(anchor.hash); // 返回'#Examples'
</script></pre>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('HTML WHATWG', '#dom-location-hash', 'hash')}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat("api.Location.hash")}}</p>
|