mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-12-17 00:04:34 +08:00
语法高亮,滚动条美化,设置页面调整
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<h2 id="Summary" name="Summary">概述</h2>
|
||||
<p><strong>charAt()</strong> 方法从一个字符串中返回指定的字符。</p>
|
||||
<h2 id="Syntax" name="Syntax">语法</h2>
|
||||
<pre class="syntaxbox"><em>str</em>.charAt(<em>index</em>)</pre>
|
||||
<pre><code class="language-javascript"><em>str</em>.charAt(<em>index</em>)</code></pre>
|
||||
<h3 id="Parameters" name="Parameters">参数</h3>
|
||||
<dl>
|
||||
<dt><code>index</code></dt>
|
||||
@@ -16,7 +16,7 @@
|
||||
<h2 id="Examples" name="Examples">示例</h2>
|
||||
<h3 id="Example:_Displaying_characters_at_different_locations_in_a_string" name="Example:_Displaying_characters_at_different_locations_in_a_string">例子:输出字符串中不同位置的字符</h3>
|
||||
<p>下例输出字符串 "<code>Brave new world</code>" 不同位置处的字符:</p>
|
||||
<pre class="brush:js">var anyString = "Brave new world";
|
||||
<pre><code class="language-js">var anyString = "Brave new world";
|
||||
|
||||
console.log("The character at index 0 is '" + anyString.charAt(0) + "'");
|
||||
console.log("The character at index 1 is '" + anyString.charAt(1) + "'");
|
||||
@@ -24,7 +24,7 @@ console.log("The character at index 2 is '" + anyString.charAt(2) + "'");
|
||||
console.log("The character at index 3 is '" + anyString.charAt(3) + "'");
|
||||
console.log("The character at index 4 is '" + anyString.charAt(4) + "'");
|
||||
console.log("The character at index 999 is '" + anyString.charAt(999) + "'");
|
||||
</pre>
|
||||
</code></pre>
|
||||
<p>上面代码的输出为:</p>
|
||||
<pre>The character at index 0 is 'B'
|
||||
The character at index 1 is 'r'
|
||||
@@ -32,10 +32,10 @@ The character at index 2 is 'a'
|
||||
The character at index 3 is 'v'
|
||||
The character at index 4 is 'e'
|
||||
The character at index 999 is ''
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="例子:获取所有字符">例子:获取所有字符</h3>
|
||||
<p>以下提供了一种确保通过字符串循环总是提供整个字符的方法,即使该字符串包含不在<a class="external" href="https://zh.wikipedia.org/wiki/Unicode%E5%AD%97%E7%AC%A6%E5%B9%B3%E9%9D%A2%E6%98%A0%E5%B0%84#.E5.9F.BA.E6.9C.AC.E5.A4.9A.E6.96.87.E7.A7.8D.E5.B9.B3.E9.9D.A2" rel="noopener">基本多文种平面</a>(BMP)中的字符。</p>
|
||||
<pre class="brush:js">var str = 'A \uD87E\uDC04 Z'; // We could also use a non-BMP character directly
|
||||
<pre><code class="language-js">var str = 'A \uD87E\uDC04 Z'; // We could also use a non-BMP character directly
|
||||
for (var i=0, chr; i < str.length; i++) {
|
||||
if ((chr = getWholeChar(str, i)) === false) {
|
||||
continue;
|
||||
@@ -84,9 +84,9 @@ function getWholeChar (str, i) {
|
||||
return false;
|
||||
}
|
||||
|
||||
</pre>
|
||||
</code></pre>
|
||||
<p>在允许解构分配的独占JavaScript 1.7+环境(如Firefox)中,以下是一个更简洁和更灵活的替代方法,它会自动递增一个递增变量(如果字符保证它是一个替代对)。</p>
|
||||
<pre class="brush: js">var str = 'A\uD87E\uDC04Z'; // We could also use a non-BMP character directly
|
||||
<pre><code class="language-javascript">var str = 'A\uD87E\uDC04Z'; // We could also use a non-BMP character directly
|
||||
for (var i=0, chr; i < str.length; i++) {
|
||||
[chr, i] = getWholeCharAndI(str, i);
|
||||
// Adapt this line at the top of each loop, passing in the whole string and
|
||||
@@ -131,10 +131,10 @@ function getWholeCharAndI (str, i) {
|
||||
}
|
||||
// Return the next character instead (and increment)
|
||||
return [str.charAt(i+1), i+1];
|
||||
}</pre>
|
||||
}</code></pre>
|
||||
<h3 id="示例:修复charAt以支持非基本多文种平面(BMP)字符">示例:修复charAt以支持非基本多文种平面(BMP)字符</h3>
|
||||
<p>虽然上面的例子对于那些希望支持非BMP字符的用户可能更有用(因为它不要求调用者知道任何非BMP字符可能出现在哪里),在人们希望的情况下,在选择字符 通过索引,将字符串中的替代对作为它们表示的单个字符,可以使用以下:</p>
|
||||
<pre class="brush: js">function fixedCharAt (str, idx) {
|
||||
<pre><code class="language-javascript">function fixedCharAt (str, idx) {
|
||||
var ret = '';
|
||||
str += '';
|
||||
var end = str.length;
|
||||
@@ -160,7 +160,7 @@ function getWholeCharAndI (str, i) {
|
||||
ret += str.charAt(idx+1);
|
||||
}
|
||||
return ret;
|
||||
}</pre>
|
||||
}</code></pre>
|
||||
<h2 id="规范">规范</h2>
|
||||
<table class="standard-table">
|
||||
<tbody>
|
||||
|
||||
Reference in New Issue
Block a user