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

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

@@ -2,7 +2,7 @@
<p></p><p></p>
<p><strong><code>substring() </code></strong>方法返回一个字符串在开始索引到结束索引之间的一个子集, 或从开始索引直到字符串的末尾的一个子集。</p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><code><var>str</var>.substring(<var>indexStart</var>[, <var>indexEnd</var>])</code></pre>
<pre><code class="language-javascript"><code><var>str</var>.substring(<var>indexStart</var>[, <var>indexEnd</var>])</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
<dt><code>indexStart</code></dt>
@@ -24,7 +24,7 @@
<h2 id="Examples" name="Examples">示例</h2>
<h3 id="Example:_Using_substring" name="Example:_Using_substring">例子:使用 <code>substring</code></h3>
<p>下例使用 <code>substring</code> 输出字符串 "<code>Mozilla</code>" 中的字符:</p>
<pre class="brush:js">var anyString = "Mozilla";
<pre><code class="language-js">var anyString = "Mozilla";
// 输出 "Moz"
console.log(anyString.substring(0,3));
@@ -47,11 +47,11 @@ console.log(anyString.substring(0,6));
// 输出 "Mozilla"
console.log(anyString.substring(0,7));
console.log(anyString.substring(0,10));
</pre>
</code></pre>
<p> </p>
<h3 id="运用_length_属性来使用_substring()"><strong>运用 length 属性来使用 substring()</strong></h3>
<p>下面一个例子运用了    String.length 属性去获取指定字符串的倒数元素。显然这个办法更容易记住,因为你不再像上面那个例子那样去记住起始位置和最终位置。</p>
<pre class="brush: js"><code>// Displays 'illa' the last 4 characters
<pre><code class="language-javascript"><code>// Displays 'illa' the last 4 characters
var anyString = 'Mozilla';
var anyString4 = anyString.substring(anyString.length - 4);
console.log(anyString4);</code>
@@ -59,11 +59,11 @@ console.log(anyString4);</code>
// Displays 'zilla' the last 5 characters
var anyString = 'Mozilla';
var anyString5 = anyString.substring(anyString.length - 5);
console.log(anyString5);</pre>
console.log(anyString5);</code></pre>
<p> </p>
<h3 id="Example:_Replacing_a_substring_within_a_string" name="Example:_Replacing_a_substring_within_a_string">例子:替换一个字符串的子字符串</h3>
<p>下例替换了一个字符串中的子字符串。可以替换单个字符和子字符串。该例结尾调用的函数将 "<code>Brave New World</code>" 变成了 "<code>Brave New Web</code>"。</p>
<pre class="brush:js">function replaceString(oldS, newS, fullS) {
<pre><code class="language-js">function replaceString(oldS, newS, fullS) {
// Replaces oldS with newS in the string fullS
for (var i = 0; i &lt; fullS.length; i++) {
if (fullS.substring(i, i + oldS.length) == oldS) {
@@ -73,11 +73,11 @@ console.log(anyString5);</pre>
return fullS;
}
replaceString("World", "Web", "Brave New World");</pre>
replaceString("World", "Web", "Brave New World");</code></pre>
<p>需要注意的是,如果 <code>oldS</code><code>newS</code> 的子字符串将会导致死循环。例如,尝试把 "World" 替换成 "OtherWorld"。一个更好的方法如下:</p>
<pre class="brush:js">function replaceString(oldS, newS,fullS){
<pre><code class="language-js">function replaceString(oldS, newS,fullS){
return fullS.split(oldS).join(newS);
}</pre>
}</code></pre>
<p><span style="line-height: 1.5;">上面的代码只是子字符串操作的一个例子。如果你需要替换子字符串,更多时候会用到 </span><span style="line-height: 1.5em;"><a href="Reference/Global_Objects/String/replace" title="replace() 方法返回一个由替换值replacement替换一些或所有匹配的模式pattern后的新字符串。模式可以是一个字符串或者一个正则表达式替换值可以是一个字符串或者一个每次匹配都要调用的回调函数。"><code>String.prototype.replace()</code></a></span></p>
<h2 id="规范">规范</h2>
<table class="standard-table">