blob: e60e1f5e4253e116fba8d4ff2cba04e50e31b021 (
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
46
47
48
49
50
51
52
|
---
title: HTMLHyperlinkElementUtils.hash
slug: Web/API/HTMLAnchorElement/hash
tags:
- HTMLHyperlinkElementUtils.hash
translation_of: Web/API/HTMLHyperlinkElementUtils/hash
original_slug: Web/API/HTMLHyperlinkElementUtils/hash
---
<p>{{ APIRef("URLUtils") }}</p>
<p><strong><code>HTMLHyperlinkElementUtils.hash</code></strong> 属性返回一个包含“#”的 {{domxref("DOMString")}} , 后跟URL的片段标识符。</p>
<p>片段没有<a href="/zh-CN/docs/Glossary/percent-encoding">百分比解码</a>。如果URL没有包含片段标识符,这个属性为一个空的字符串, <code>""</code>.</p>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox"><em>string</em> = <em>object</em>.hash;
<em>object</em>.hash = <em>string</em>;
</pre>
<h2 id="Examples">Examples</h2>
<pre class="brush: js">// Let's an <a id="myAnchor" href="https://developer.mozilla.org/en-US/docs/HTMLHyperlinkElementUtils.href#youhou"> element be in the document
var anchor = document.getElementById("myAnchor");
var result = anchor.hash; // Returns:'#youhou'</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-hyperlink-hash', 'HTMLHyperlinkElementUtils.hash')}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
{{Compat("api.HTMLAnchorElement.hash")}}
<h2 id="See_also">See also</h2>
<ul>
<li>The {{domxref("HTMLHyperlinkElementUtils")}} interface it belongs to.</li>
</ul>
|