aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/history/go/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/history/go/index.html')
-rw-r--r--files/zh-cn/web/api/history/go/index.html77
1 files changed, 77 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/history/go/index.html b/files/zh-cn/web/api/history/go/index.html
new file mode 100644
index 0000000000..a6fe7b38a8
--- /dev/null
+++ b/files/zh-cn/web/api/history/go/index.html
@@ -0,0 +1,77 @@
+---
+title: go()
+slug: Web/API/History/go
+tags:
+ - History
+translation_of: Web/API/History/go
+---
+<p><code>go()</code>方法从会话历史记录中加载特定页面。你可以使用它在历史记录中前后移动,具体取决于<code>delta</code>参数的值。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="brush: js">window.history.go(delta);</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><code>delta</code> {{optional_inline}}</dt>
+ <dd>相对于当前页面你要去往历史页面的位置。负值表示向后移动,正值表示向前移动。因此,例如:<code>history.go(2)</code>向前移动两页,<code>history.go(-2)</code>则向后移动两页。如果未向该函数传参或<code>delta</code>相等于0,则该函数与调用<code>location.reload()</code>具有相同的效果。</dd>
+ <dt>
+ <div class="blockIndicator note">
+ <p>译者注:</p>
+
+ <p>相等于0是采用宽松相等进行比较的。另外,JavaScript值古怪的隐式转换在这里也是可用的。</p>
+ </div>
+ </dt>
+</dl>
+
+<h2 id="示例">示例</h2>
+
+<p>向后移动一页(等价于调用<a href="https://developer.mozilla.org/en-US/docs/Web/API/History/back" title="The back method moves back one page in the session history. If there is no previous page, this method call does nothing."><code>back()</code></a>):</p>
+
+<pre class="brush: js line-numbers language-js"><code class="language-js">window<span class="punctuation token">.</span>history<span class="punctuation token">.</span><span class="function token">go</span><span class="punctuation token">(</span><span class="operator token">-</span><span class="number token">1</span><span class="punctuation token">)</span></code></pre>
+
+<p>向前移动一页,就像调用了<a href="https://developer.mozilla.org/en-US/docs/Web/API/History/forward" title="Moves forward one page in the session history. It has the same effect as calling history.go() with a delta parameter of 1."><code>forward()</code>:</a></p>
+
+<pre class="brush: js line-numbers language-js"><code class="language-js">window<span class="punctuation token">.</span>history<span class="punctuation token">.</span><span class="function token">go</span><span class="punctuation token">(</span><span class="number token">1</span><span class="punctuation token">)</span></code></pre>
+
+<p>向前移动两页:</p>
+
+<pre class="brush: js">window.history.go(2);</pre>
+
+<p>向后移动两页:</p>
+
+<pre class="brush: js">window.history.go(-2);</pre>
+
+<p>最后,以下任意一条语句都会重新加载当前页面:</p>
+
+<pre class="brush: js">window.history.go();
+window.history.go(0);</pre>
+
+<h2 id="规范">规范</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", "browsers.html#history", "History")}}</td>
+ <td>{{Spec2("HTML WHATWG")}}</td>
+ <td>No change from {{SpecName("HTML5 W3C")}}.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName("HTML5 W3C", "browsers.html#history", "History")}}</td>
+ <td>{{Spec2("HTML5 W3C")}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("api.History.go")}}</p>