104 lines
4.1 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<article id="wikiArticle">
<div><div class="blockIndicator obsolete obsoleteHeader"><p><strong><span class="icon-only-inline" title="This is an obsolete API and is no longer guaranteed to work."><i class="icon-trash"> </i></span> 已废弃 Gecko 37 (Firefox 37 / Thunderbird 37 / SeaMonkey 2.34)</strong><br/>This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.</p></div></div>
<div><div class="blockIndicator nonStandard nonStandardHeader">
<p><strong><span class="icon-only-inline" title="This API has not been standardized."><i class="icon-warning-sign"> </i></span> 非标准</strong><br/>
该特性是非标准的,请尽量不要在生产环境中使用它!</p>
</div></div>
<h2 id="Summary" name="Summary">概述</h2>
<p>将字符串中包含的特殊字符进行转义(反斜杠),然后在字符串两边各加上一个双引号(<code>"</code>)并返回,并不修改原字符串.</p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre><code class="language-javascript"><code><em>str</em>.quote()</code></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 class="new" href="/zh-CN/docs/JavaScript/Reference/Global_Objects/eval" rel="nofollow" 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><div class="blockIndicator warning"><strong><a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">We're converting our compatibility data into a machine-readable JSON format</a></strong>.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
<strong><a class="new" href="/zh-CN/docs/MDN/Contribute/Structures/Compatibility_tables" rel="nofollow">Find out how you can help!</a></strong></div>
<div class="htab">
<a id="AutoCompatibilityTable" name="AutoCompatibilityTable"></a>
<ul>
<li class="selected"><a>Desktop</a></li>
<li><a>Mobile</a></li>
</ul>
</div></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><span style="color: #f00;">未实现</span></td>
<td><span style="color: #f00;">未实现</span></td>
<td><span style="color: #f00;">未实现</span></td>
<td><span style="color: #f00;">未实现</span></td>
<td><span style="color: #f00;">未实现</span></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><span style="color: #f00;">未实现</span></td>
<td><span style="color: #f00;">未实现</span></td>
<td><span style="color: #f00;">未实现</span></td>
<td><span style="color: #f00;">未实现</span></td>
<td><span style="color: #f00;">未实现</span></td>
<td><span style="color: #f00;">未实现</span></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>
</article>