aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/url/tostring/index.html
blob: 090bdf2be1ecd5ecfb8ce1880ad3ae82055167e5 (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
---
title: URL.toString()
slug: Web/API/URL/toString
tags:
  - API
  - URL
  - 参考
  - 字符串
  - 方法
translation_of: Web/API/URL/toString
---
<div>{{ApiRef("URL API")}}</div>

<p><strong><code>URL.toString()</code></strong> 字符串化方法返回一个包含完整 URL 的 {{domxref("USVString")}}。它的作用等同于只读的 {{domxref("URL.href")}}</p>

<p>{{AvailableInWorkers}}</p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox"><em>string</em> = <em>url</em>.toString();</pre>

<h3 id="参数">参数</h3>

<p>无。</p>

<h3 id="返回值">返回值</h3>

<p>一个{{domxref("USVString")}}</p>

<h2 id="参考">参考</h2>

<pre class="brush: js"><span class="message-body-wrapper"><span class="message-flex-body"><span class="devtools-monospace message-body"><span class="cm-keyword">const</span> <span class="cm-def">url</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">URL</span>(<span class="cm-string">"https://developer.mozilla.org/en-US/docs/Web/API/URL/toString"</span>);
<span class="cm-variable">url</span>.<span class="cm-property">toString</span>() // 应当返回字符串形式的 URL</span></span></span>
</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('URL', '#URL-stringification-behavior', 'stringifier')}}</td>
   <td>{{Spec2('URL')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>



<p>{{Compat("api.URL.toString")}}</p>

<h2 id="参见">参见</h2>

<ul>
 <li>父级接口 {{domxref("URL")}}</li>
</ul>