diff options
author | Irvin <irvinfly@gmail.com> | 2022-02-16 02:02:49 +0800 |
---|---|---|
committer | Irvin <irvinfly@gmail.com> | 2022-02-16 02:35:54 +0800 |
commit | 01b0e12ba27b5069248fd09235e9a7143915ee30 (patch) | |
tree | 0e9edf538dc3fa3331e1dbb79239b58186765f86 /files/zh-cn/web/javascript/reference/global_objects/string | |
parent | 6ca84f1794af830ada9736d7289ce29aabb04ca3 (diff) | |
download | translated-content-01b0e12ba27b5069248fd09235e9a7143915ee30.tar.gz translated-content-01b0e12ba27b5069248fd09235e9a7143915ee30.tar.bz2 translated-content-01b0e12ba27b5069248fd09235e9a7143915ee30.zip |
remove `notranslate` class in zh-CN
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/string')
21 files changed, 86 insertions, 86 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/charcodeat/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/charcodeat/index.html index 8c683db768..e0c7b1168f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/charcodeat/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/charcodeat/index.html @@ -22,7 +22,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/charCodeAt <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><code><em>str</em>.charCodeAt(<em>index</em>)</code></pre> +<pre class="syntaxbox"><code><em>str</em>.charCodeAt(<em>index</em>)</code></pre> <h3 id="参数">参数</h3> @@ -55,7 +55,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/charCodeAt <p>下例介绍了不同索引情况下返回的 Unicode 值:</p> -<pre class="brush: js notranslate">"ABC".charCodeAt(0) // returns 65:"A" +<pre class="brush: js">"ABC".charCodeAt(0) // returns 65:"A" "ABC".charCodeAt(1) // returns 66:"B" @@ -67,7 +67,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/charCodeAt <p>这段代码可以被用在 for 循环和其他类似语句中,当在指定引索之前不确定是否有非BMP字符存在时。</p> -<pre class="brush:js notranslate">function fixedCharCodeAt (str, idx) { +<pre class="brush:js">function fixedCharCodeAt (str, idx) { // ex. fixedCharCodeAt ('\uD800\uDC00', 0); // 65536 // ex. fixedCharCodeAt ('\uD800\uDC00', 1); // false idx = idx || 0; @@ -98,7 +98,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/charCodeAt <h3 id="使用_charCodeAt_修复字符串中出现的已知的非BMP字符">使用 <code>charCodeAt()</code> 修复字符串中出现的已知的非BMP字符</h3> -<pre class="brush:js notranslate">function knownCharCodeAt (str, idx) { +<pre class="brush:js">function knownCharCodeAt (str, idx) { str += ''; var code, end = str.length; diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.html index ee2d8dd06d..7b53403ac2 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.html @@ -14,7 +14,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/concat <h2 id="Syntax" name="Syntax">语法</h2> -<pre class="notranslate"><code><var>str</var>.concat(<var>str2</var>, [, ...<var>strN</var>])</code></pre> +<pre><code><var>str</var>.concat(<var>str2</var>, [, ...<var>strN</var>])</code></pre> <h3 id="Parameters" name="Parameters">参数</h3> @@ -43,7 +43,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/concat <p>下面的例子演示如何将多个字符串与原字符串合并为一个新字符串</p> -<pre class="brush: js notranslate">let hello = 'Hello, ' +<pre class="brush: js">let hello = 'Hello, ' console.log(hello.concat('Kevin', '. Have a nice day.')) // Hello, Kevin. Have a nice day. diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/endswith/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/endswith/index.html index fb6728a8a0..dd5597701e 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/endswith/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/endswith/index.html @@ -23,7 +23,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/endsWith <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><var>str</var>.endsWith(<var>searchString</var>[, <var>length</var>])</pre> +<pre class="syntaxbox"><var>str</var>.endsWith(<var>searchString</var>[, <var>length</var>])</pre> <h3 id="参数">参数</h3> @@ -46,7 +46,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/endsWith <p>这个方法已经加入到 ECMAScript 6 标准当中,但是可能还没有在所有的 JavaScript 实现中可用。然而,你可以通过如下的代码片段扩展 <code>String.prototype.endsWith()</code> 实现兼容:</p> -<pre class="brush: js notranslate">if (!String.prototype.endsWith) { +<pre class="brush: js">if (!String.prototype.endsWith) { String.prototype.endsWith = function(search, this_len) { if (this_len === undefined || this_len > this.length) { this_len = this.length; @@ -60,7 +60,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/endsWith <h3 id="使用_endsWith">使用 <code>endsWith()</code></h3> -<pre class="brush:js; notranslate">var str = "To be, or not to be, that is the question."; +<pre class="brush:js;">var str = "To be, or not to be, that is the question."; alert( str.endsWith("question.") ); // true alert( str.endsWith("to be") ); // false diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/fromcharcode/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/fromcharcode/index.html index fd399adab7..3ac0a6a122 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/fromcharcode/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/fromcharcode/index.html @@ -16,7 +16,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/fromCharCode <h2 id="Syntax" name="Syntax">语法</h2> -<pre class="syntaxbox notranslate"><code>String.fromCharCode(<var>num1</var>[, ...[, <var>numN</var>]])</code></pre> +<pre class="syntaxbox"><code>String.fromCharCode(<var>num1</var>[, ...[, <var>numN</var>]])</code></pre> <h3 id="Parameters" name="Parameters">参数</h3> @@ -49,7 +49,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/fromCharCode <p>在 UTF-16 中,BMP 字符使用一个代码单元:</p> -<pre class="brush: js notranslate">String.fromCharCode(65, 66, 67); // 返回 "ABC" +<pre class="brush: js">String.fromCharCode(65, 66, 67); // 返回 "ABC" String.fromCharCode(0x2014); // 返回 "—" String.fromCharCode(0x12014); // 也是返回 "—"; 数字 1 被剔除并忽略 String.fromCharCode(8212); // 也是返回 "—"; 8212 是 0x2014 的十进制表示 @@ -58,7 +58,7 @@ String.fromCharCode(8212); // 也是返回 "—"; 8212 是 0x2014 的十 <p><a href="https://asecuritysite.com/coding/asc2">完整的 UTF 16 表格</a>.<br> 在 UTF-16 中,补充字符需要两个代码单元(即一个代理对):</p> -<pre class="brush: js notranslate">String.fromCharCode(0xD83C, 0xDF03); // Code Point U+1F303 "Night with +<pre class="brush: js">String.fromCharCode(0xD83C, 0xDF03); // Code Point U+1F303 "Night with String.fromCharCode(55356, 57091); // Stars" == "\uD83C\uDF03" String.fromCharCode(0xD834, 0xDF06, 0x61, 0xD834, 0xDF07); // "\uD834\uDF06a\uD834\uDF07" diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/includes/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/includes/index.html index 83ced4b38a..672a34166f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/includes/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/includes/index.html @@ -16,7 +16,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/includes <h2 id="Syntax" name="Syntax">语法</h2> -<pre class="syntaxbox notranslate"><var>str</var>.includes(<var>searchString</var>[, <var>position</var>])</pre> +<pre class="syntaxbox"><var>str</var>.includes(<var>searchString</var>[, <var>position</var>])</pre> <h3 id="参数">参数</h3> @@ -39,13 +39,13 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/includes <p><code>includes()</code> 方法是区分大小写的。例如,下面的表达式会返回 <strong><code>false</code></strong> :</p> -<pre class="notranslate"><code>'Blue Whale'.includes('blue'); // returns false</code></pre> +<pre><code>'Blue Whale'.includes('blue'); // returns false</code></pre> <h2 id="兼容补丁">兼容补丁</h2> <p>这个方法已经被加入到 ECMAScript 6 标准中,但未必在所有的 JavaScript 实现中都可以使用。然而,你可以轻松地 polyfill 这个方法:</p> -<pre class="notranslate"><code>if (!String.prototype.includes) { +<pre><code>if (!String.prototype.includes) { String.prototype.includes = function(search, start) { 'use strict'; if (typeof start !== 'number') { @@ -64,7 +64,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/includes <h3 id="使用_includes">使用 includes()</h3> -<pre class="notranslate"><code>var str = 'To be, or not to be, that is the question.'; +<pre><code>var str = 'To be, or not to be, that is the question.'; console.log(str.includes('To be')); // true console.log(str.includes('question')); // true diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/indexof/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/indexof/index.html index 21434132e5..80213be40f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/indexof/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/indexof/index.html @@ -22,7 +22,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/indexOf <h2 id="语法">语法</h2> -<pre class="notranslate"><var>str</var>.indexOf(<var>searchValue [</var>, <var>fromIndex]</var>)</pre> +<pre><var>str</var>.indexOf(<var>searchValue [</var>, <var>fromIndex]</var>)</pre> <h3 id="参数">参数</h3> @@ -43,14 +43,14 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/indexOf <p>若被查找的字符串 <code><var>searchValue</var></code><var> </var>是一个空字符串,将会产生“奇怪”的结果。如果 <code>fromIndex</code> 值为空,或者 <code>fromIndex</code> 值小于被查找的字符串的长度,返回值和以下的 <code>fromIndex</code> 值一样:</p> -<pre class="brush: js notranslate">'hello world'.indexOf('') // 返回 0 +<pre class="brush: js">'hello world'.indexOf('') // 返回 0 'hello world'.indexOf('', 0) // 返回 0 'hello world'.indexOf('', 3) // 返回 3 'hello world'.indexOf('', 8) // 返回 8</pre> <p>另外,如果 <code>fromIndex</code> 值大于等于字符串的长度,将会直接返回字符串的长度(<code>str.length</code>):</p> -<pre class="brush: js notranslate">'hello world'.indexOf('', 11) // 返回 11 +<pre class="brush: js">'hello world'.indexOf('', 11) // 返回 11 'hello world'.indexOf('', 13) // 返回 11 'hello world'.indexOf('', 22) // 返回 11</pre> @@ -60,7 +60,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/indexOf <p>字符串中的字符被从左向右索引。第一个字符的索引(index)是 <code>0</code>,变量名为 <code>stringName</code> 的字符串的最后一个字符的索引是 <code>stringName.length - 1</code> 。</p> -<pre class="brush: js notranslate">"Blue Whale".indexOf("Blue") // 返回 0 +<pre class="brush: js">"Blue Whale".indexOf("Blue") // 返回 0 "Blue Whale".indexOf("Blute") // 返回 -1 "Blue Whale".indexOf("Whale", 0) // 返回 5 "Blue Whale".indexOf("Whale", 5) // 返回 5 @@ -71,14 +71,14 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/indexOf <p id="Example_indexOf_and_case-sensitivity"><code>indexOf</code> 方法是区分大小写的。例如,下面的表达式将返回 <code>-1</code>:</p> -<pre class="brush: js notranslate">"Blue Whale".indexOf("blue") // 返回 -1 +<pre class="brush: js">"Blue Whale".indexOf("blue") // 返回 -1 </pre> <h3 id="检测是否存在某字符串">检测是否存在某字符串</h3> <p>注意 <code>0</code> 并不会被当成 <code>true</code> ,<code>-1</code> 不会被当成 <code>false</code> 。所以当检测某个字符串是否存在于另一个字符串中时,可使用下面的方法:</p> -<pre class="notranslate">'Blue Whale'.indexOf('Blue') !== -1 // true +<pre>'Blue Whale'.indexOf('Blue') !== -1 // true 'Blue Whale'.indexOf('Bloe') !== -1 // false ~('Blue Whale'.indexOf('Bloe')) // 0, 这是一种错误用法</pre> @@ -88,7 +88,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/indexOf <p>下例使用 <code>indexOf()</code> 和 <code>lastIndexOf()</code> 方法定位字符串中 "<code>Brave new world</code>" 的值。</p> -<pre class="brush: js notranslate">var anyString = "Brave new world"; +<pre class="brush: js">var anyString = "Brave new world"; console.log("The index of the first w from the beginning is " + anyString.indexOf("w")); // logs 8 @@ -105,7 +105,7 @@ console.log("The index of 'new' from the end is " + anyString.lastIndexOf("new") <p>下例定义了两个字符串变量。两个变量包含相同的字符串,除了第二个字符串中的某些字符为大写。第一个 <code>log</code> 方法输出 19。但是由于 <code>indexOf</code> 方法区分大小写,因此不会在 <code>myCapString</code> 中发现字符串 <code>“cheddar"</code>,所以,第二个 <code>log</code> 方法会输出 -1。</p> -<pre class="brush: js notranslate">var myString = "brie, pepper jack, cheddar"; +<pre class="brush: js">var myString = "brie, pepper jack, cheddar"; var myCapString = "Brie, Pepper Jack, Cheddar"; console.log('myString.indexOf("cheddar") is ' + myString.indexOf("cheddar")); @@ -117,7 +117,7 @@ console.log('myCapString.indexOf("cheddar") is ' + myCapString.indexOf("cheddar" <p>在下例中,设置了 <code>count</code> 来记录字母 <code>e</code> 在字符串 <code>str</code> 中出现的次数:</p> -<pre class="brush: js notranslate">// 翻译:生存还是毁灭?这是个问题。(莎士比亚《哈姆雷特》) +<pre class="brush: js">// 翻译:生存还是毁灭?这是个问题。(莎士比亚《哈姆雷特》) var str = 'To be, or not to be, that is the question.'; var count = 0; var pos = str.indexOf('e'); diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/localecompare/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/localecompare/index.html index 1bdd45c95e..bf0e8ad0fb 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/localecompare/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/localecompare/index.html @@ -19,7 +19,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/localeCompare <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><code><var>referenceStr</var>.localeCompare(<var>compareString</var>[, <var>locales</var>[, <var>options</var>]])</code></pre> +<pre class="syntaxbox"><code><var>referenceStr</var>.localeCompare(<var>compareString</var>[, <var>locales</var>[, <var>options</var>]])</code></pre> <h3 id="参数">参数</h3> @@ -90,7 +90,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/localeCompare <h3 id="使用_localeCompare">使用 <code>localeCompare()</code></h3> -<pre class="brush: js notranslate">// The letter "a" is before "c" yielding a negative value +<pre class="brush: js">// The letter "a" is before "c" yielding a negative value 'a'.localeCompare('c'); // -2 or -1 (or some other negative value) @@ -107,7 +107,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/localeCompare <p><code>locales</code> 和 <code>options</code> 参数还没有被所有浏览器所支持。检查是否被支持, 使用 "i" 参数 (a requirement that illegal language tags are rejected) 判断是否有异常 {{jsxref("RangeError")}}抛出:</p> -<pre class="brush: js notranslate">function localeCompareSupportsLocales() { +<pre class="brush: js">function localeCompareSupportsLocales() { try { 'foo'.localeCompare('bar', 'i'); } catch (e) { @@ -121,7 +121,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/localeCompare <p>在不同的语言下 <code>localeCompare()</code> 所提供的结果是不一致的。 为了能让用户得到正确的比较值, 通过使用 <code>locales</code> 参数来提供要比较的语言 (and possibly some fallback languages) :</p> -<pre class="brush: js notranslate">console.log('ä'.localeCompare('z', 'de')); // a negative value: in German, ä sorts with a +<pre class="brush: js">console.log('ä'.localeCompare('z', 'de')); // a negative value: in German, ä sorts with a console.log('ä'.localeCompare('z', 'sv')); // a positive value: in Swedish, ä sorts after z </pre> @@ -129,7 +129,7 @@ console.log('ä'.localeCompare('z', 'sv')); // a positive value: in Swedish, ä <p><code>localeCompare()</code> 所提供的结果可以通过 <code>options</code> 参数来制定:</p> -<pre class="brush: js notranslate">// in German, ä has a as the base letter +<pre class="brush: js">// in German, ä has a as the base letter console.log('ä'.localeCompare('a', 'de', { sensitivity: 'base' })); // 0 // in Swedish, ä and a are separate base letters diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/match/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/match/index.html index cc979f7ffe..5f5b701e63 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/match/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/match/index.html @@ -14,7 +14,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/match <h2 id="Syntax" name="Syntax">语法</h2> -<pre class="syntaxbox notranslate"><code><em>str</em>.match(regexp)</code></pre> +<pre class="syntaxbox"><code><em>str</em>.match(regexp)</code></pre> <h3 id="Parameters" name="Parameters">参数</h3> @@ -62,7 +62,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/match <p>在下例中,使用 <code>match</code> 查找 "<code>Chapter</code>" 紧跟着 1 个或多个数值字符,再紧跟着一个小数点和数值字符 0 次或多次。正则表达式包含 <code>i</code> 标志,因此大小写会被忽略。</p> -<pre class="brush: js line-numbers language-js notranslate"><code class="language-js">var str = 'For more information, see Chapter 3.4.5.1'; +<pre class="brush: js line-numbers language-js"><code class="language-js">var str = 'For more information, see Chapter 3.4.5.1'; var re = /see (chapter \d+(\.\d)*)/i; var found = str.match(re); @@ -84,7 +84,7 @@ console.log(found); <p>下例展示了 <code>match</code> 使用 global 和 ignore case 标志。A-E、a-e 的所有字母将会作为一个数组的元素返回。</p> -<pre class="brush: js line-numbers language-js notranslate"><code class="language-js">var str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; +<pre class="brush: js line-numbers language-js"><code class="language-js">var str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; var regexp = /[A-E]/gi; var matches_array = str.match(regexp); @@ -93,7 +93,7 @@ console.log(matches_array); <h3 id="使用match,不传参数"><code>使用match(),不传参数 </code></h3> -<pre class="brush: js line-numbers language-js notranslate"><code class="language-js">var str = "Nothing will come of nothing."; +<pre class="brush: js line-numbers language-js"><code class="language-js">var str = "Nothing will come of nothing."; str.match(); // returns [""]</code></pre> @@ -101,7 +101,7 @@ str.match(); // returns [""]</code></pre> <p>当参数是一个字符串或一个数字,它会使用new RegExp(obj)来隐式转换成一个 {{jsxref("RegExp")}}。如果它是一个有正号的正数,RegExp() 方法将忽略正号。</p> -<pre class="brush: js line-numbers language-js notranslate"><code class="language-js">var str1 = "NaN means not a number. Infinity contains -Infinity and +Infinity in JavaScript.", +<pre class="brush: js line-numbers language-js"><code class="language-js">var str1 = "NaN means not a number. Infinity contains -Infinity and +Infinity in JavaScript.", str2 = "My grandfather is 65 years old and My grandmother is 63 years old.", str3 = "The contract was declared null and void."; str1.match("number"); // "number" 是字符串。返回["number"] diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/matchall/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/matchall/index.html index f2344f6f79..d11d23265e 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/matchall/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/matchall/index.html @@ -20,7 +20,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/matchAll <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><var>str</var>.matchAll(<var>regexp</var>)</pre> +<pre class="syntaxbox"><var>str</var>.matchAll(<var>regexp</var>)</pre> <h3 id="参数">参数</h3> @@ -42,7 +42,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/matchAll <p>在 <code>matchAll</code> 出现之前,通过在循环中调用 <code>regexp.exec()</code> 来获取所有匹配项信息(regexp 需使用 <code>/g</code> 标志):</p> -<pre class="brush: js notranslate">const regexp = RegExp('foo[a-z]*','g'); +<pre class="brush: js">const regexp = RegExp('foo[a-z]*','g'); const str = 'table football, foosball'; let match; @@ -54,7 +54,7 @@ while ((match = regexp.exec(str)) !== null) { <p>如果使用 <code>matchAll</code> ,就可以不必使用 while 循环加 exec 方式(且正则表达式需使用 <code>/g</code> 标志)。使用 <code>matchAll</code> 会得到一个迭代器的返回值,配合 <code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...of">for...of</a></code>, <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax">array spread</a>, 或者 {{jsxref("Array.from()")}} 可以更方便实现功能:</p> -<pre class="brush: js notranslate">const regexp = RegExp('foo[a-z]*','g'); +<pre class="brush: js">const regexp = RegExp('foo[a-z]*','g'); const str = 'table football, foosball'; const matches = str.matchAll(regexp); @@ -71,14 +71,14 @@ Array.from(str.matchAll(regexp), m => m[0]); <p>如果没有 <code>/g</code> 标志,<code>matchAll</code> 会抛出异常。</p> -<pre class="brush: js notranslate">const regexp = RegExp('[a-c]',''); +<pre class="brush: js">const regexp = RegExp('[a-c]',''); const str = 'abc'; Array.from(str.matchAll(regexp), m => m[0]); // TypeError: String.prototype.matchAll called with a non-global RegExp argument</pre> <p><code>matchAll</code> 内部做了一个 regexp 的复制,所以不像 <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec">regexp.exec</a>, <code>lastIndex</code> 在字符串扫描时不会改变。</p> -<pre class="brush: js notranslate">const regexp = RegExp('[a-c]','g'); +<pre class="brush: js">const regexp = RegExp('[a-c]','g'); regexp.lastIndex = 1; const str = 'abc'; Array.from(str.matchAll(regexp), m => `${regexp.lastIndex} ${m[0]}`); @@ -89,7 +89,7 @@ Array.from(str.matchAll(regexp), m => `${regexp.lastIndex} ${m[0]}`); <p><code>matchAll</code> 的另外一个亮点是更好地获取捕获组。因为当使用 <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match">match()</a></code> 和 <code>/g</code> 标志方式获取匹配信息时,捕获组会被忽略:</p> -<pre class="brush: js notranslate">var regexp = /t(e)(st(\d?))/g; +<pre class="brush: js">var regexp = /t(e)(st(\d?))/g; var str = 'test1test2'; str.match(regexp); @@ -97,7 +97,7 @@ str.match(regexp); <p>使用 <code>matchAll</code> 可以通过如下方式获取分组捕获:</p> -<pre class="brush: js notranslate">let array = [...str.matchAll(regexp)]; +<pre class="brush: js">let array = [...str.matchAll(regexp)]; array[0]; // ['test1', 'e', 'st1', '1', index: 0, input: 'test1test2', length: 4] diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/padend/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/padend/index.html index ca1f5d8515..e73b847c5b 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/padend/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/padend/index.html @@ -18,7 +18,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/padEnd <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><var>str</var>.padEnd(<var>targetLength</var> [, <var>padString</var>])</pre> +<pre class="syntaxbox"><var>str</var>.padEnd(<var>targetLength</var> [, <var>padString</var>])</pre> <h3 id="参数">参数</h3> @@ -35,7 +35,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/padEnd <h2 id="示例">示例</h2> -<pre class="brush: js notranslate">'abc'.padEnd(10); // "abc " +<pre class="brush: js">'abc'.padEnd(10); // "abc " 'abc'.padEnd(10, "foo"); // "abcfoofoof" 'abc'.padEnd(6, "123456"); // "abc123" 'abc'.padEnd(1); // "abc" @@ -45,7 +45,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/padEnd <p>如果原生环境不支持该方法,在其他代码之前先运行下面的代码,将创建 <code>String.prototype.padEnd()</code> 方法。</p> -<pre class="brush: js notranslate">// https://github.com/uxitten/polyfill/blob/master/string.polyfill.js +<pre class="brush: js">// https://github.com/uxitten/polyfill/blob/master/string.polyfill.js // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd if (!String.prototype.padEnd) { String.prototype.padEnd = function padEnd(targetLength,padString) { diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/padstart/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/padstart/index.html index 8596df0ae3..69aff06b94 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/padstart/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/padstart/index.html @@ -20,7 +20,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/padStart <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><var>str</var>.padStart(<var>targetLength</var> [, <var>padString</var>])</pre> +<pre class="syntaxbox"><var>str</var>.padStart(<var>targetLength</var> [, <var>padString</var>])</pre> <h3 id="参数">参数</h3> @@ -37,7 +37,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/padStart <h2 id="示例">示例</h2> -<pre class="brush: js line-numbers language-js notranslate"><code class="language-js">'abc'.padStart(10); // " abc" +<pre class="brush: js line-numbers language-js"><code class="language-js">'abc'.padStart(10); // " abc" 'abc'.padStart(10, "foo"); // "foofoofabc" 'abc'.padStart(6,"123465"); // "123abc" 'abc'.padStart(8, "0"); // "00000abc" @@ -47,7 +47,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/padStart <p>如果原生环境不支持该方法,在其他代码之前先运行下面的代码,将创建 <code>String.prototype.padStart()</code> 方法。</p> -<pre class="brush: js line-numbers language-js notranslate"><code class="language-js">// https://github.com/uxitten/polyfill/blob/master/string.polyfill.js +<pre class="brush: js line-numbers language-js"><code class="language-js">// https://github.com/uxitten/polyfill/blob/master/string.polyfill.js // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart if (!String.prototype.padStart) { String.prototype.padStart = function padStart(targetLength,padString) { diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/repeat/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/repeat/index.html index b880c16b92..c0ee77fe21 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/repeat/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/repeat/index.html @@ -20,7 +20,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/repeat <h2 id="Syntax" name="Syntax">语法</h2> -<pre class="syntaxbox notranslate"><code><var>str</var>.repeat(<var>count</var>)</code></pre> +<pre class="syntaxbox"><code><var>str</var>.repeat(<var>count</var>)</code></pre> <h3 id="Parameters" name="Parameters">参数</h3> @@ -44,7 +44,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/repeat <p>此方法已添加到 ECMAScript 2015 规范中,并且可能尚未在所有 JavaScript 实现中可用。然而,你可以使用以下代码段对 String.prototype.repeat() 进行填充:</p> -<pre class="brush: js language-js notranslate"><code class="language-js">if (!String.prototype.repeat) { +<pre class="brush: js language-js"><code class="language-js">if (!String.prototype.repeat) { String.prototype.repeat = function(count) { 'use strict'; if (this == null) { @@ -88,7 +88,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/repeat <h2 id="Examples" name="Examples">示例</h2> -<pre class="brush:js notranslate">"abc".repeat(-1) // RangeError: repeat count must be positive and less than inifinity +<pre class="brush:js">"abc".repeat(-1) // RangeError: repeat count must be positive and less than inifinity "abc".repeat(0) // "" "abc".repeat(1) // "abc" "abc".repeat(2) // "abcabc" diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/replace/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/replace/index.html index 49f27efe4b..5991e8fa0a 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/replace/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/replace/index.html @@ -21,7 +21,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/replace <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><code><var>str</var>.replace(<var>regexp</var>|<var>substr</var>, <var>newSubStr</var>|<var>function</var>)</code></pre> +<pre class="syntaxbox"><code><var>str</var>.replace(<var>regexp</var>|<var>substr</var>, <var>newSubStr</var>|<var>function</var>)</code></pre> <h3 id="参数">参数</h3> @@ -137,7 +137,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/replace <p>下面的例子将会使 <code>newString</code> 变成 <code>'abc - 12345 - #$*%'</code>:</p> -<pre class="brush: js notranslate">function replacer(match, p1, p2, p3, offset, string) { +<pre class="brush: js">function replacer(match, p1, p2, p3, offset, string) { // p1 is nondigits, p2 digits, and p3 non-alphanumerics return [p1, p2, p3].join(' - '); } @@ -151,7 +151,7 @@ console.log(newString); // abc - 12345 - #$*% <p>在下面的例子中,<code>replace()</code> 中使用了正则表达式及忽略大小写标示。</p> -<pre class="brush: js notranslate">var str = 'Twas the night before Xmas...'; +<pre class="brush: js">var str = 'Twas the night before Xmas...'; var newstr = str.replace(/xmas/i, 'Christmas'); console.log(newstr); // Twas the night before Christmas... </pre> @@ -160,7 +160,7 @@ console.log(newstr); // Twas the night before Christmas... <p>下面的例子中,正则表达式包含有全局替换(g)和忽略大小写(i)的选项,这使得replace方法用'oranges'替换掉了所有出现的"apples".</p> -<pre class="brush: js notranslate">var re = /apples/gi; +<pre class="brush: js">var re = /apples/gi; var str = "Apples are round, and apples are juicy."; var newstr = str.replace(re, "oranges"); @@ -172,7 +172,7 @@ console.log(newstr); <p>下面的例子演示了如何交换一个字符串中两个单词的位置,这个脚本使用$1 和 $2 代替替换文本。</p> -<pre class="brush: js notranslate">var re = /(\w+)\s(\w+)/; +<pre class="brush: js">var re = /(\w+)\s(\w+)/; var str = "John Smith"; var newstr = str.replace(re, "$2, $1"); // Smith, John @@ -185,7 +185,7 @@ console.log(newstr); <p>在返回前,替换函数允许匹配片段作为参数,并且将它和连字符进行连接作为新的片段。</p> -<pre class="brush: js notranslate">function styleHyphenFormat(propertyName) { +<pre class="brush: js">function styleHyphenFormat(propertyName) { function upperToHyphenLower(match) { return '-' + match.toLowerCase(); } @@ -197,7 +197,7 @@ console.log(newstr); <p>因为我们想在最终的替换中进一步转变匹配结果,所以我们必须使用一个函数。这迫使我们在使用{{jsxref("String.prototype.toLowerCase()", "toLowerCase()")}}方法前进行评估。如果我们尝试不用一个函数进行匹配,那么使用{{jsxref("String.prototype.toLowerCase()", "toLowerCase()")}} 方法将不会有效。</p> -<pre class="brush: js notranslate">var newString = propertyName.replace(/[A-Z]/g, '-' + '$&'.toLowerCase()); // won't work +<pre class="brush: js">var newString = propertyName.replace(/[A-Z]/g, '-' + '$&'.toLowerCase()); // won't work </pre> <p>这是因为 <code>'$&'.toLowerCase()</code> 会先被解析成字符串字面量(这会导致相同的'$&')而不是当作一个模式。</p> @@ -208,7 +208,7 @@ console.log(newstr); <p>正则表达式test检查任何数字是否以 F 结尾。华氏温度通过第二个参数p1进入函数。这个函数基于华氏温度作为字符串传递给f2c函数设置成摄氏温度。然后f2c()返回摄氏温度。这个函数与Perl的 s///e 标志相似。</p> -<pre class="brush: js notranslate">function f2c(x) +<pre class="brush: js">function f2c(x) { function convert(str, p1, offset, s) { @@ -227,7 +227,7 @@ console.log(newstr); <p><strong>输入:</strong><br> 一个由 x,- 和 _ 组成的字符串。</p> -<pre class="notranslate">x-x_ +<pre>x-x_ ---x---x---x--- @@ -240,7 +240,7 @@ _x_x___x___x___ <p>一个数组对象。'x' 产生一个 'on' 状态,'-'(连接符)产生一个 'off' 状态,而 '_' (下划线)表示 'on' 状态的长度。</p> -<pre class="brush: js notranslate">[ +<pre class="brush: js">[ { on: true, length: 1 }, { on: false, length: 1 }, { on: true, length: 2 } @@ -249,7 +249,7 @@ _x_x___x___x___ <p>代码片段:</p> -<pre class="brush: js notranslate">var str = 'x-x_'; +<pre class="brush: js">var str = 'x-x_'; var retArr = []; str.replace(/(x_*)|(-)/g, function(match, p1, p2) { if (p1) { retArr.push({ on: true, length: p1.length }); } diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/replaceall/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/replaceall/index.html index cbd76d71b7..c9d892e3f7 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/replaceall/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/replaceall/index.html @@ -19,7 +19,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/replaceAll <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate">const newStr = <var>str</var>.replaceAll(<var>regexp</var>|<var>substr</var>, <var>newSubstr</var>|<var>function</var>)</pre> +<pre class="syntaxbox">const newStr = <var>str</var>.replaceAll(<var>regexp</var>|<var>substr</var>, <var>newSubstr</var>|<var>function</var>)</pre> <div class="blockIndicator note"> <p>当使用一个 `regex`时,您必须设置全局(“ g”)标志,<br> @@ -123,20 +123,20 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/replaceAll <h3 id="使用_replaceAll">使用 replaceAll</h3> -<pre class="brush: js notranslate">'aabbcc'.replaceAll('b', '.'); +<pre class="brush: js">'aabbcc'.replaceAll('b', '.'); // 'aa..cc'</pre> <h3 id="非全局_regex_抛出">非全局 regex 抛出</h3> <p>使用正则表达式搜索值时,它必须是全局的。这将行不通:</p> -<pre class="brush: js; example-bad notranslate">'aabbcc'.replaceAll(/b/, '.'); +<pre class="brush: js; example-bad">'aabbcc'.replaceAll(/b/, '.'); TypeError: replaceAll must be called with a global RegExp </pre> <p>这将可以正常运行:</p> -<pre class="brush: js; example-good notranslate">'aabbcc'.replaceAll(/b/g, '.'); +<pre class="brush: js; example-good">'aabbcc'.replaceAll(/b/g, '.'); "aa..cc" </pre> diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/search/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/search/index.html index 06c7e214fd..35a75549c2 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/search/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/search/index.html @@ -20,7 +20,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/search <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><var>str</var>.search(<var>regexp</var>)</pre> +<pre class="syntaxbox"><var>str</var>.search(<var>regexp</var>)</pre> <h3 id="参数">参数</h3> @@ -44,7 +44,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/search <p>下面的例子中用两个不同的正则表达式对同一个字符串执行搜索匹配,得到一个成功匹配(正数返回值)和一个失败匹配(-1)。</p> -<pre class="brush: js notranslate">var str = "hey JudE"; +<pre class="brush: js">var str = "hey JudE"; var re = /[A-Z]/g; var re2 = /[.]/g; console.log(str.search(re)); // returns 4, which is the index of the first capital letter "J" diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/startswith/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/startswith/index.html index 7cbd48ba7b..ac60af390f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/startswith/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/startswith/index.html @@ -21,7 +21,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/startsWith <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><var>str</var>.startsWith(<var>searchString</var>[, <var>position</var>])</pre> +<pre class="syntaxbox"><var>str</var>.startsWith(<var>searchString</var>[, <var>position</var>])</pre> <h3 id="参数">参数</h3> @@ -44,7 +44,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/startsWith <p>此方法已被添加至 ECMAScript 2015 规范之中,但可能不能在所有的现行 JavaScript 实现中使用。不过,你可以用以下的代码段为 <code>String.prototype.startsWith()</code> 制作 Polyfill:</p> -<pre class="brush: js notranslate">if (!String.prototype.startsWith) { +<pre class="brush: js">if (!String.prototype.startsWith) { Object.defineProperty(String.prototype, 'startsWith', { value: function(search, pos) { pos = !pos || pos < 0 ? 0 : +pos; @@ -60,7 +60,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/startsWith <h3 id="使用_startsWith">使用 <code>startsWith()</code></h3> -<pre class="brush:js; notranslate">var str = "To be, or not to be, that is the question."; +<pre class="brush:js;">var str = "To be, or not to be, that is the question."; alert(str.startsWith("To be")); // true alert(str.startsWith("not to be")); // false diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/substring/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/substring/index.html index e2b061d1a3..f35badbe86 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/substring/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/substring/index.html @@ -11,7 +11,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/substring <h2 id="Syntax" name="Syntax">语法</h2> -<pre class="syntaxbox notranslate"><code><var>str</var>.substring(<var>indexStart</var>[, <var>indexEnd</var>])</code></pre> +<pre class="syntaxbox"><code><var>str</var>.substring(<var>indexStart</var>[, <var>indexEnd</var>])</code></pre> <h3 id="Parameters" name="Parameters">参数</h3> @@ -44,7 +44,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/substring <p>下例使用 <code>substring</code> 输出字符串 "<code>Mozilla</code>" 中的字符:</p> -<pre class="brush:js notranslate">var anyString = "Mozilla"; +<pre class="brush:js">var anyString = "Mozilla"; // 输出 "Moz" console.log(anyString.substring(0,3)); @@ -73,7 +73,7 @@ console.log(anyString.substring(0,10)); <p>下面一个例子运用了 String.length 属性去获取指定字符串的倒数元素。显然这个办法更容易记住,因为你不再像上面那个例子那样去记住起始位置和最终位置。</p> -<pre class="brush: js notranslate"><code>// Displays 'illa' the last 4 characters +<pre class="brush: js"><code>// Displays 'illa' the last 4 characters var anyString = 'Mozilla'; var anyString4 = anyString.substring(anyString.length - 4); console.log(anyString4);</code> @@ -87,7 +87,7 @@ console.log(anyString5);</pre> <p>下例替换了一个字符串中的子字符串。可以替换单个字符和子字符串。该例结尾调用的函数将 "<code>Brave New World</code>" 变成了 "<code>Brave New Web</code>"。</p> -<pre class="brush:js notranslate">function replaceString(oldS, newS, fullS) { +<pre class="brush:js">function replaceString(oldS, newS, fullS) { // Replaces oldS with newS in the string fullS for (var i = 0; i < fullS.length; i++) { if (fullS.substring(i, i + oldS.length) == oldS) { @@ -101,7 +101,7 @@ replaceString("World", "Web", "Brave New World");</pre> <p>需要注意的是,如果 <code>oldS</code> 是 <code>newS</code> 的子字符串将会导致死循环。例如,尝试把 "Web" 替换成 "OtherWorld"。一个更好的方法如下:</p> -<pre class="brush:js notranslate">function replaceString(oldS, newS,fullS){ +<pre class="brush:js">function replaceString(oldS, newS,fullS){ return fullS.split(oldS).join(newS); }</pre> diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/tolowercase/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/tolowercase/index.html index 007d9bb2d9..b1b9f6266d 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/tolowercase/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/tolowercase/index.html @@ -15,7 +15,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/toLowerCase <h2 id="语法" style="margin-bottom: 20px; line-height: 30px;">语法</h2> -<pre class="syntaxbox language-html notranslate" style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; direction: ltr; white-space: normal; text-shadow: none; background-color: rgba(212, 221, 228, 0.498039);"><code class="language-html" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; direction: ltr; color: inherit; text-shadow: none;">str.toLowerCase()</code> +<pre class="syntaxbox language-html" style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; direction: ltr; white-space: normal; text-shadow: none; background-color: rgba(212, 221, 228, 0.498039);"><code class="language-html" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; direction: ltr; color: inherit; text-shadow: none;">str.toLowerCase()</code> </pre> <p id="sect1"></p> @@ -32,7 +32,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/toLowerCase <h3 id="例子:使用_toLowerCase" style="line-height: 24px;">例子:使用 <code>toLowerCase()</code></h3> -<pre class="brush: js notranslate">console.log('中文简体 zh-CN || zh-Hans'.toLowerCase()); +<pre class="brush: js">console.log('中文简体 zh-CN || zh-Hans'.toLowerCase()); // 中文简体 zh-cn || zh-hans console.log( "ALPHABET".toLowerCase() ); diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/touppercase/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/touppercase/index.html index 0e45f82bac..820f1a80b3 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/touppercase/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/touppercase/index.html @@ -19,7 +19,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/toUpperCase <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><var>str</var>.toUpperCase()</pre> +<pre class="syntaxbox"><var>str</var>.toUpperCase()</pre> <h3 id="返回值">返回值</h3> @@ -40,14 +40,14 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/toUpperCase <h3 id="基本用法">基本用法</h3> -<pre class="brush: js notranslate">console.log('alphabet'.toUpperCase()); // 'ALPHABET' +<pre class="brush: js">console.log('alphabet'.toUpperCase()); // 'ALPHABET' </pre> <h3 id="将非字符串类型的_this_(上下文)转为字符串">将非字符串类型的 <code>this</code> (上下文)转为字符串</h3> <p>此方法会将任何非字符串类型的值转为字符串, 当你将其上下文 <code>this</code> 值设置为非字符串类型</p> -<pre class="brush: js notranslate">const a = String.prototype.toUpperCase.call({ +<pre class="brush: js">const a = String.prototype.toUpperCase.call({ toString: function toString() { return 'abcdef'; } diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/trim/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/trim/index.html index 503a9e234f..aa0e524f53 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/trim/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/trim/index.html @@ -26,7 +26,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/Trim <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><code><var>str</var>.trim()</code></pre> +<pre class="syntaxbox"><code><var>str</var>.trim()</code></pre> <h3 id="返回值">返回值</h3> @@ -42,7 +42,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/Trim <p>下面的例子中将显示小写的字符串 'foo':</p> -<pre class="brush: js notranslate">var orig = ' foo '; +<pre class="brush: js">var orig = ' foo '; console.log(orig.trim()); // 'foo' // 另一个 .trim() 例子,只从一边删除 @@ -55,7 +55,7 @@ console.log(orig.trim()); // 'foo' <p>如果 <code>trim()</code> 不存在,可以在所有代码前执行下面代码</p> -<pre class="brush: js notranslate">if (!String.prototype.trim) { +<pre class="brush: js">if (!String.prototype.trim) { String.prototype.trim = function () { return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); }; diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/valueof/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/valueof/index.html index 6af5bd5d2d..2d8754a2cc 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/valueof/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/valueof/index.html @@ -11,7 +11,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/valueOf <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><code><var>str</var>.valueOf()</code></pre> +<pre class="syntaxbox"><code><var>str</var>.valueOf()</code></pre> <h3 id="返回结果">返回结果</h3> @@ -27,7 +27,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/valueOf <h3 id="使用_valueOf">使用 <code>valueOf()</code></h3> -<pre class="brush: js notranslate">var x = new String('Hello world'); +<pre class="brush: js">var x = new String('Hello world'); console.log(x.valueOf()); // Displays 'Hello world' </pre> |