blob: 25608cd5eefae9f0d283f4373cd17020b2dee399 (
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
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
|
---
title: String.prototype.anchor()
slug: Web/JavaScript/Reference/Global_Objects/String/anchor
tags:
- HTML
- JavaScript
- Method
- Prototype
- String
translation_of: Web/JavaScript/Reference/Global_Objects/String/anchor
---
<div>{{JSRef("Global_Objects", "String")}}</div>
<h2 id="概述">概述</h2>
<div class="warning">
<p><strong>警告:</strong>该特性已经从 Web 标准中删除,虽然一些浏览器目前仍然支持它,但也许会在未来的某个时间停止支持,请尽量不要使用该特性。</p>
</div>
<p><code><strong>anchor()</strong></code> 方法创建一个 {{HTMLElement("a")}} HTML 锚元素,被用作超文本靶标(hypertext target)。</p>
<h2>语法</h2>
<pre class="syntaxbox"><code>str.anchor(<em>name</em>) </code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>name</code></dt>
<dd>一个字符串,表示被创建的标签的 <code>name</code> 属性。</dd>
</dl>
<h3 id="返回值">返回值</h3>
<p> 包含 {{HTMLElement("a")}} HTML元素的一个字符串。</p>
<h2 id="描述">描述</h2>
<p>使用 <code>anchor</code> 方法能够以编程方式在一个文档中创建和展现一个锚链接。</p>
<p>语法上来讲,字符串表示你想让用户看到的文本。<code>name</code> 字符串参数表示 {{HTMLElement("a")}} 元素的 <code>name</code> 属性。</p>
<p>使用 anchor 方法创建的锚点(anchors)将会成为 {{domxref("document.anchors")}} 数组的元素。</p>
<h2 id="示例">示例</h2>
<h3 id="例子:使用_anchor">例子:使用 <code>anchor</code></h3>
<pre class="brush:js">var myString = "Table of Contents";
document.body.innerHTML = myString.anchor("contents_anchor");</pre>
<p>将会输出下面的 HTML:</p>
<pre class="brush: html"><a name="contents_anchor">Table of Contents</a></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">规范</th>
<th scope="col">状态</th>
<th scope="col">注释</th>
</tr>
<tr>
<td>{{SpecName('ES6', '#sec-string.prototype.anchor', 'String.prototype.anchor')}}</td>
<td>{{Spec2('ES6')}}</td>
<td>Initial definition. Implemented in JavaScript 1.0.<br>
Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers.</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
{{Compat}}
<h2 id="See_Also">相关链接</h2>
<ul>
<li>{{jsxref("String.prototype.link()")}}</li>
</ul>
|