blob: 3d8d197f46bf6079cc8561701e1e454e3004cf9e (
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
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
|
---
title: String.prototype.quote()
slug: Web/JavaScript/Reference/Global_Objects/String/quote
tags:
- JavaScript
- Method
- Non-standard
- Obsolete
- Prototype
- String
translation_of: Archive/Web/JavaScript/String.quote
---
<div>{{obsolete_header("37")}}</div>
<div>{{JSRef("Global_Objects", "String")}}{{Non-standard_header}}</div>
<h2 id="Summary" name="Summary">概述</h2>
<p>将字符串中包含的特殊字符进行转义(反斜杠),然后在字符串两边各加上一个双引号(<code>"</code>)并返回,并不修改原字符串.</p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><code><em>str</em>.quote()</code></pre>
<h2 id="Examples" name="Examples">示例</h2>
<table class="fullwidth-table">
<thead>
<tr>
<th class="header" scope="col"><code>str</code></th>
<th class="header" scope="col"><code>str.quote()</code></th>
<th class="header" scope="col"><code><a href="/zh-CN/docs/JavaScript/Reference/Global_Objects/eval" title="JavaScript/Reference/Global_Objects/eval">eval</a>(str.quote())</code></th>
</tr>
</thead>
<tbody>
<tr>
<td><code>Hello world!</code></td>
<td><code>"Hello world!"</code></td>
<td><code>Hello world!</code></td>
</tr>
<tr>
<td><code>Hello<br>
world!</code></td>
<td><code>"Hello\n\tworld!"</code></td>
<td><code>Hello<br>
world!</code></td>
</tr>
<tr>
<td><code>" \ — '</code></td>
<td><code>"\" \\ \u2014 '"</code></td>
<td><code>" \ — '</code></td>
</tr>
</tbody>
</table>
<h2 id="Specifications" name="Specifications">规范</h2>
<p>不在任何规范中。实现于 JavaScript 1.3.</p>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<div>{{CompatibilityTable}}</div>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Chrome</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
</tr>
<tr>
<td>Basic support</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Android</th>
<th>Chrome for Android</th>
<th>Firefox Mobile (Gecko)</th>
<th>IE Mobile</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>Basic support</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
</tr>
</tbody>
</table>
</div>
<h2 id="See_also" name="See_also">相关链接</h2>
<ul>
<li><code><a href="/zh-CN/docs/JavaScript/Reference/Global_Objects/JSON/stringify" title="JavaScript/Reference/Global_Objects/JSON/stringify">JSON.stringify</a></code></li>
</ul>
|