语法高亮,滚动条美化,设置页面调整

This commit is contained in:
fofolee
2019-04-19 02:41:09 +08:00
parent 1e8f76c000
commit 359d29ee0b
1590 changed files with 12328 additions and 11441 deletions

View File

@@ -4,7 +4,7 @@
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/date-tolocaledatestring.html" width="100%"></iframe></div>
<p class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a class="external" href="https://github.com/mdn/interactive-examples" rel="noopener">https://github.com/mdn/interactive-examples</a> and send us a pull request.</p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><var>dateObj</var>.toLocaleDateString([locales [, options]])</pre>
<pre><code class="language-javascript"><var>dateObj</var>.toLocaleDateString([locales [, options]])</code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p> 查看<a href="#Browser_Compatibility" title="#Browser_Compatibility">浏览器兼容性</a>小节,看下哪些浏览器支持 <code>locales</code> 和 <code>options</code> 参数,还可以参看<a href="#Example:_Checking_for_support_for_locales_and_options_arguments">例子: 检测 <code>locales</code><code>options</code> 参数支持情况</a></p>
<p></p><dl>
@@ -107,15 +107,15 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Using_toLocaleDateString" name="Example:_Using_toLocaleDateString">例子:使用<code>toLocaleDateString</code></h3>
<p>没有指定语言环境locale返回一个使用默认语言环境和格式设置options的格式化字符串。</p>
<pre class="brush:js">var date = new Date(Date.UTC(2012, 11, 12, 3, 0, 0));
<pre><code class="language-js">var date = new Date(Date.UTC(2012, 11, 12, 3, 0, 0));
// toLocaleDateString without arguments depends on the implementation,
// the default locale, and the default time zone
date.toLocaleDateString();
// → "12/11/2012" if run in en-US locale with time zone America/Los_Angeles</pre>
// → "12/11/2012" if run in en-US locale with time zone America/Los_Angeles</code></pre>
<h3 id="Example:_Checking_for_support_for_locales_and_options_arguments" name="Example:_Checking_for_support_for_locales_and_options_arguments">例子:检测 <code>locales</code><code>options</code> 参数支持情况</h3>
<p><code>locales</code> 和 <code>options</code> 参数不是所有的浏览器都支持。为了检测一种实现环境implementation是否支持它们可以使用不合法的语言标签如果实现环境支持该参数则会抛出一个 <code>RangeError</code> 异常,反之会忽略参数。</p>
<pre class="brush: js">function toLocaleDateStringSupportsLocales() {
<pre><code class="language-javascript">function toLocaleDateStringSupportsLocales() {
try {
new Date().toLocaleDateString("i");
} catch (e) {
@@ -123,10 +123,10 @@ date.toLocaleDateString();
}
return false;
}
</pre>
</code></pre>
<h3 id="Example:_Using_locales" name="Example:_Using_locales">例子:使用<code>locales</code></h3>
<p>下例展示了本地化日期格式的一些变化。为了在应用的用户界面得到某种语言的日期格式,必须确保使用 <code>locales</code> 参数指定了该语言(可能还需要设置某些回退语言)。</p>
<pre class="brush: js">var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
<pre><code class="language-javascript">var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
// formats below assume the local time zone of the locale;
// America/Los_Angeles for the US
@@ -156,10 +156,10 @@ alert(date.toLocaleDateString("ja-JP-u-ca-japanese"));
// Balinese, include a fallback language, in this case Indonesian
alert(date.toLocaleDateString(["ban", "id"]));
// → "20/12/2012"
</pre>
</code></pre>
<h3 id="Example:_Using_options" name="Example:_Using_options">例子:使用<code>options</code></h3>
<p>可以使用 <code>options </code>参数来自定义 <code>toLocaleDateString</code> 方法返回的字符串。</p>
<pre class="brush: js">var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
<pre><code class="language-javascript">var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
// request a weekday along with a long date
var options = {weekday: "long", year: "numeric", month: "long", day: "numeric"};
@@ -171,7 +171,7 @@ options.timeZone = "UTC";
options.timeZoneName = "short";
alert(date.toLocaleDateString("en-US", options));
// → "Thursday, December 20, 2012, GMT"
</pre>
</code></pre>
<h2 id="Performance" name="Performance">性能</h2>
<p>当格式化大量日期时,最好创建一个 <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat" title="/en-US/docs/JavaScript/Reference/Global_Objects/DateTimeFormat"><code>Intl.DateTimeFormat</code></a> 对象,然后使用该对象 <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format" title="/en-US/docs/JavaScript/Reference/Global_Objects/DateTimeFormat/format"><code>format</code></a> 属性提供的方法。</p>
<h2 id="规范">规范</h2>