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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
---
title: HTMLAnchorElement
slug: Web/API/HTMLAnchorElement
translation_of: Web/API/HTMLAnchorElement
---
<div>{{APIRef("HTML DOM")}}</div>
<p><strong><code>HTMLAnchorElement</code></strong> 接口表示超链接元素,并提供一些特别的属性和方法(除了那些继承自普通 {{domxref("HTMLElement")}}对象接口的之外)以用于操作这些元素的布局和显示。</p>
<h2 id="属性(Properties)">属性(Properties)</h2>
<p><em>继承其父类 {{domxref("HTMLElement")}} 的属性,并实现 {{domxref("URLUtils")}} 中(定义)的(属性)。</em></p>
<dl>
<dt>{{domxref("HTMLAnchorElement.accessKey")}}</dt>
<dd>是一个代表了单个字符的 {{domxref("DOMString")}},单个字符可以切换输入焦点到超链接。</dd>
<dt>{{domxref("HTMLAnchorElement.charset")}} {{obsolete_inline}}</dt>
<dd>Is a {{domxref("DOMString")}} representing the character encoding of the linked resource.</dd>
<dt>{{domxref("HTMLAnchorElement.coords")}} {{obsolete_inline}}</dt>
<dd>Is a {{domxref("DOMString")}} representing a comma-separated list of coordinates.</dd>
<dt>{{domxref("HTMLAnchorElement.download")}} {{experimental_inline}}</dt>
<dd>Is a {{domxref("DOMString")}} indicating that the linked resource is intended to be downloaded rather than displayed in the browser. The value represent the proposed name of the file. If the name is not a valid filename of the underlying OS, browser will adapt it. The value is a URL with a scheme like <code>http:</code>, <code>file:</code>, <code>data:</code> or even <code>blob:</code> (created with {{domxref("URL.createObjectURL")}}).</dd>
<dt>{{domxref("URLUtils.hash")}}</dt>
<dd>Is a {{domxref("DOMString")}} representing the fragment identifier, including the leading hash mark ('<code>#</code>'), if any, in the referenced URL.</dd>
<dt>{{domxref("URLUtils.host")}}</dt>
<dd>Is a {{domxref("DOMString")}} representing the hostname and port (if it's not the default port) in the referenced URL.</dd>
<dt>{{domxref("URLUtils.hostname")}}</dt>
<dd>Is a {{domxref("DOMString")}} representing the hostname in the referenced URL.</dd>
<dt>{{domxref("URLUtils.href")}}</dt>
<dd>Is a {{domxref("DOMString")}} that reflects the {{htmlattrxref("href", "a")}} HTML attribute, containing a valid URL of a linked resource.</dd>
<dt>{{domxref("HTMLAnchorElement.hreflang")}}</dt>
<dd>Is a {{domxref("DOMString")}} that reflects the {{htmlattrxref("hreflang", "a")}} HTML attribute, indicating the language of the linked resource.</dd>
<dt>{{domxref("HTMLAnchorElement.media")}}</dt>
<dd>Is a {{domxref("DOMString")}} that reflects the {{htmlattrxref("media", "a")}} HTML attribute, indicating the intended media for the linked resource.</dd>
<dt>{{domxref("HTMLAnchorElement.name")}} {{obsolete_inline}}</dt>
<dd>Is a {{domxref("DOMString")}} representing the anchor name.</dd>
<dt>{{domxref("URLUtils.passport")}}</dt>
<dd>Is a {{domxref("DOMString")}} 包含指定域名的密码。</dd>
<dt>{{domxref("URLUtils.origin")}} {{readonlyInline}}</dt>
<dd>Returns a {{domxref("DOMString")}} containing the origin of the URL, that is its scheme, its domain and its port.</dd>
<dt>{{domxref("URLUtils.pathname")}}</dt>
<dd>Is a {{domxref("DOMString")}} representing the path name component, if any, of the referenced URL.</dd>
<dt>{{domxref("URLUtils.port")}}</dt>
<dd>Is a {{domxref("DOMString")}} representing the port component, if any, of the referenced URL.</dd>
<dt>{{domxref("URLUtils.protocol")}}</dt>
<dd>Is a {{domxref("DOMString")}} representing the protocol component, including trailing colon ('<code>:</code>'), of the referenced URL.</dd>
<dt>{{domxref("HTMLAnchorElement.rel")}}</dt>
<dd>Is a {{domxref("DOMString")}} that reflects the {{htmlattrxref("rel", "a")}} HTML attribute, specifying the relationship of the target object to the linked object.</dd>
<dt>{{domxref("HTMLAnchorElement.relList")}} {{readonlyInline}}</dt>
<dd>Returns a {{domxref("DOMTokenList")}} that reflects the {{htmlattrxref("rel", "a")}} HTML attribute, as a list of tokens.</dd>
<dt>{{domxref("HTMLAnchorElement.rev")}} {{obsolete_inline}}</dt>
<dd>Is a {{domxref("DOMString")}} representing that the {{htmlattrxref("rev", "a")}} HTML attribute, specifying the relationship of the link object to the target object.</dd>
<dt>{{domxref("URLUtils.search")}}</dt>
<dd>Is a {{domxref("DOMString")}} representing tThe search element, including leading question mark ('<code>?</code>'), if any, of the referenced URL.</dd>
<dt>{{domxref("HTMLAnchorElement.shape")}} {{obsolete_inline}}</dt>
<dd>Is a {{domxref("DOMString")}} representing the shape of the active area.</dd>
<dt>{{domxref("HTMLAnchorElement.tabindex")}}</dt>
<dd>Is a <code>long</code> containing the position of the element in the tabbing navigation order for the current document.</dd>
<dt>{{domxref("HTMLAnchorElement.target")}}</dt>
<dd>Is a {{domxref("DOMString")}} that reflects the {{htmlattrxref("target", "a")}} HTML attribute, indicating where to display the linked resource.</dd>
<dt>{{domxref("HTMLAnchorElement.text")}}</dt>
<dd>Is a {{domxref("DOMString")}} being a synonym for the {{domxref("Node.textContent")}} property.</dd>
<dt>{{domxref("HTMLAnchorElement.type")}}</dt>
<dd>Is a {{domxref("DOMString")}} that reflects the {{htmlattrxref("type", "a")}} HTML attribute, indicating the MIME type of the linked resource.</dd>
<dt>{{domxref("URLUtils.username")}}</dt>
<dd>Is a {{domxref("DOMString")}} containing the username specified before the domain name.</dd>
</dl>
<h2 id="Methods">Methods</h2>
<p><em>Inherits methods from its parent, {{domxref("HTMLElement")}}, </em><em>and implements those from {{domxref("URLUtils")}}</em><em>.</em></p>
<dl>
<dt>{{domxref("HTMLElement.blur()")}}</dt>
<dd>Removes the keyboard focus from the current element.</dd>
<dt>{{domxref("HTMLElement.focus()")}}</dt>
<dd>Gives the keyboard focus to the current element.</dd>
<dt>{{domxref("URLUtils.toString()")}}</dt>
<dd>Returns a {{domxref("DOMString")}} containing the whole URL. It is a synonym for {{domxref("URLUtils.href")}}, though it can't be used to modify the value.</dd>
</dl>
<p>The <code>blur()</code> and <code>focus()</code> methods are inherited from {{domxref("HTMLElement")}} from HTML5 on, but were defined on <code>HTMLAnchorElement</code> in DOM Level 2 HTML and earlier specifications.</p>
<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', "text-level-semantics.html#the-a-element", "HTMLAnchorElement")}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
<td>The following property has been added: <code>download</code>.<br>
Technically, the URL-related properties, <code>media</code>, <code>host</code>, <code>hostname</code>, <code>pathname</code>, <code>port</code>, <code>protocol</code>, <code>search</code>, and <code>hash</code>, have been moved to the {{domxref("URLUtils")}} interface, and <code>HTMLAreaElement</code> implements this interface.</td>
</tr>
<tr>
<td>{{SpecName('HTML5 W3C', "text-level-semantics.html#the-a-element", "HTMLAnchorElement")}}</td>
<td>{{Spec2('HTML5 W3C')}}</td>
<td>The methods <code>blur()</code> and <code>focus()</code>, as well as the properties <code>tabindex</code> and <code>accessKey</code>, are now defined on {{domxref("HTMLElement")}}.<br>
The following properties are now obsolete: <code>charset</code>, <code>coords</code>, <code>name</code>, <code>rev</code>, and <code>shape</code>.<br>
The following properties have been added: <code>hash</code>, <code>host</code>, <code>hostname</code>, <code>media</code>, <code>pathname</code>, <code>port</code>, <code>protocol</code>, <code>relList</code>, <code>search</code>, and <code>text</code>.</td>
</tr>
<tr>
<td>{{SpecName('DOM2 HTML', 'html.html#ID-48250443', 'HTMLAnchorElement')}}</td>
<td>{{Spec2('DOM2 HTML')}}</td>
<td>No change from {{SpecName("DOM1")}}.</td>
</tr>
<tr>
<td>{{SpecName('DOM1', 'level-one-html.html#ID-48250443', 'HTMLAnchorElement')}}</td>
<td>{{Spec2('DOM1')}}</td>
<td>Initial definition.</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
{{Compat("api.HTMLAnchorElement")}}
<h2 id="See_also">See also</h2>
<ul>
<li>The HTML element implementing this interface: {{HTMLElement("a")}}</li>
</ul>
|