aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/string/tolocaleuppercase/index.html
blob: d6fe58b0a596306f2da4d997f35edb6b15fc55f0 (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
---
title: String.prototype.toLocaleUpperCase()
slug: Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase
translation_of: Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase
---
<div>{{JSRef}}</div>

<p><strong><code>toLocaleUpperCase()</code></strong> 方法根据本地主机语言环境把字符串转换为大写格式,并返回转换后的字符串。</p>

<div>{{EmbedInteractiveExample("pages/js/string-tolocaleuppercase.html")}}</div>



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

<pre class="syntaxbox"><var>str</var>.toLocaleUpperCase()
<var>str</var>.toLocaleUpperCase(locale)
<var>str</var>.toLocaleUpperCase([locale, locale, ...])
</pre>

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

<dl>
 <dt><code>locale</code> {{optional_inline}}</dt>
 <dd>The <code>locale</code> parameter indicates the locale to be used to convert to upper case according to any locale-specific case mappings. If multiple locales are given in an {{jsxref("Array")}}, the <a href="https://tc39.github.io/ecma402/#sec-bestavailablelocale">best available locale</a> is used. The default locale is the host environment’s current locale.</dd>
</dl>

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

<p>A new string representing the calling string converted to upper case, according to any locale-specific case mappings.</p>

<h3 id="Exceptions">Exceptions</h3>

<ul>
 <li>A {{jsxref("RangeError")}} ("invalid language tag: xx_yy") is thrown if a <code>locale</code> argument isn't a valid language tag.</li>
 <li>A {{jsxref("TypeError")}} ("invalid element in locales argument") is thrown if an array element isn't of type string.</li>
</ul>

<h2 id="描述">描述</h2>

<p>The <code>toLocaleUpperCase()</code> method returns the value of the string converted to upper case according to any locale-specific case mappings. <code>toLocaleUpperCase()</code> does not affect the value of the string itself. In most cases, this will produce the same result as {{jsxref("String.prototype.toUpperCase()", "toUpperCase()")}}, but for some locales, such as Turkish, whose case mappings do not follow the default case mappings in Unicode, there may be a different result.</p>

<p>Also notice that conversion is not necessarily a 1:1 character mapping, as some characters might result in two (or even more) characters when transformed to upper-case. Therefore the length of the result string can differ from the input length. This also implies that the conversion is not stable, so i.E. the following can return <code>false</code>:<br>
 <code>x.toLocaleLowerCase() === x.toLocaleUpperCase().toLocaleLowerCase()</code></p>

<h2 id="例子">例子</h2>

<h3 id="使用_toLocaleUpperCase">使用 <code>toLocaleUpperCase()</code></h3>

<pre class="brush: js">'alphabet'.toLocaleUpperCase(); // 'ALPHABET'

'Gesäß'.toLocaleUpperCase(); // 'GESÄSS'

'i\u0307'.toLocaleUpperCase('lt-LT'); // 'I'

let locales = ['lt', 'LT', 'lt-LT', 'lt-u-co-phonebk', 'lt-x-lietuva'];
'i\u0307'.toLocaleUpperCase(locales); // 'I'</pre>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">规范</th>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-string.prototype.tolocaleuppercase', 'String.prototype.toLocaleUpperCase')}}</td>
  </tr>
  <tr>
   <td>{{SpecName('ES Int Draft', '#sup-string.prototype.tolocaleuppercase', 'String.prototype.toLocaleUpperCase')}}</td>
  </tr>
 </tbody>
</table>

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

<p>{{Compat("javascript.builtins.String.toLocaleUpperCase")}}</p>

<h2 id="相关链接">相关链接</h2>

<ul>
 <li>{{jsxref("String.prototype.toLocaleLowerCase()")}}</li>
 <li>{{jsxref("String.prototype.toLowerCase()")}}</li>
 <li>{{jsxref("String.prototype.toUpperCase()")}}</li>
</ul>

<div id="gtx-trans" style="position: absolute; left: 11px; top: 96px;">
<div class="gtx-trans-icon"></div>
</div>