mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2026-03-09 15:30:30 +08:00
语法高亮,滚动条美化,设置页面调整
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<p><code><strong>toLocaleString()</strong></code> 返回一个字符串表示数组中的元素。数组中的元素将使用各自的 <code>toLocaleString</code> 方法转成字符串,这些字符串将使用一个特定语言环境的字符串(例如一个逗号 ",")隔开。</p>
|
||||
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/array-tolocalestring.html" width="100%"></iframe></div>
|
||||
<h2 id="Syntax" name="Syntax">语法</h2>
|
||||
<pre class="syntaxbox"><font face="consolas, Liberation Mono, courier, monospace">arr.toLocaleString([locales[,options]]);</font></pre>
|
||||
<pre><code class="language-javascript"><font face="consolas, Liberation Mono, courier, monospace">arr.toLocaleString([locales[,options]]);</font></code></pre>
|
||||
<h3 id="参数"><font face="consolas, Liberation Mono, courier, monospace">参数</font></h3>
|
||||
<dl>
|
||||
<dt><code>locales</code> <span class="inlineIndicator optional optionalInline">可选</span></dt>
|
||||
@@ -22,13 +22,13 @@
|
||||
<li><code>Date</code>: <a href="Reference/Global_Objects/Date/toLocaleString" title="toLocaleString() 方法返回该日期对象的字符串,该字符串格式因不同语言而不同。新增的参数 locales 和 options 使程序能够指定使用哪种语言格式化规则,允许定制该方法的表现(behavior)。在旧版本浏览器中, locales 和 options 参数被忽略,使用的语言环境和返回的字符串格式是各自独立实现的。"><code>Date.prototype.toLocaleString()</code></a></li>
|
||||
</ul>
|
||||
<p>总是在<code>prices</code>数组中显示字符串和数字的货币符号:</p>
|
||||
<pre class="brush: js">var prices = ['¥7', 500, 8123, 12];
|
||||
<pre><code class="language-javascript">var prices = ['¥7', 500, 8123, 12];
|
||||
prices.toLocaleString('ja-JP', { style: 'currency', currency: 'JPY' });
|
||||
|
||||
// "¥7,¥500,¥8,123,¥12"</pre>
|
||||
// "¥7,¥500,¥8,123,¥12"</code></pre>
|
||||
<p>更多实例请看 <a href="Reference/Global_Objects/Intl" title="Intl 对象是 ECMAScript 国际化 API 的一个命名空间,它提供了精确的字符串对比、数字格式化,和日期时间格式化。Collator,NumberFormat 和 DateTimeFormat 对象的构造函数是 Intl 对象的属性。本页文档内容包括了这些属性,以及国际化使用的构造器和其他语言的方法等常见的功能。"><code>Intl</code></a>,<a href="Reference/Global_Objects/NumberFormat" title="Intl.NumberFormat是对语言敏感的格式化数字类的构造器类"><code>NumberFormat</code></a>和<a href="Reference/Global_Objects/DateTimeFormat" title="交互示例的源代码存储在 GitHub 资源库。如果你愿意分布交互示例,请复制https://github.com/mdn/interactive-examples,并向我们发送一个pull请求。"><code>DateTimeFormat</code></a>页面。</p>
|
||||
<h2 id="Polyfill">Polyfill</h2>
|
||||
<pre class="brush: js">// https://tc39.github.io/ecma402/#sup-array.prototype.tolocalestring
|
||||
<pre><code class="language-javascript">// https://tc39.github.io/ecma402/#sup-array.prototype.tolocalestring
|
||||
if (!Array.prototype.toLocaleString) {
|
||||
Object.defineProperty(Array.prototype, 'toLocaleString', {
|
||||
value: function(locales, options) {
|
||||
@@ -109,7 +109,7 @@ if (!Array.prototype.toLocaleString) {
|
||||
}
|
||||
});
|
||||
}
|
||||
</pre>
|
||||
</code></pre>
|
||||
<p>如果你需要支持真正不支持<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty">Object.defineProperty</a></code>的JavaScript引擎,最好不要对<code>Array.prototype</code>方法进行填充,因为你不能使它们不可枚举。</p>
|
||||
<h2 id="规范">规范</h2>
|
||||
<table class="standard-table">
|
||||
|
||||
Reference in New Issue
Block a user