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

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

@@ -6,8 +6,8 @@
<p>注意对于String方法请参阅 <a href="Reference/Global_Objects/String/indexOf" title="indexOf() 方法返回调用  String 对象中第一次出现的指定值的索引开始在 fromIndex进行搜索。"><code>String.prototype.indexOf()</code></a></p>
</div>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><code><em>arr</em>.indexOf(<em>searchElement</em>)
<em>arr</em>.indexOf(<em>searchElement</em>[, <em>fromIndex = 0</em>])</code></pre>
<pre><code class="language-javascript"><code><em>arr</em>.indexOf(<em>searchElement</em>)
<em>arr</em>.indexOf(<em>searchElement</em>[, <em>fromIndex = 0</em>])</code></code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>searchElement</code></dt>
@@ -22,15 +22,15 @@
<h2 id="示例">示例</h2>
<h3 id="使用indexOf">使用indexOf</h3>
<p>以下例子使用<code>indexOf方法确定多个值在数组中的位置。</code></p>
<pre class="brush: js">var array = [2, 5, 9];
<pre><code class="language-javascript">var array = [2, 5, 9];
array.indexOf(2); // 0
array.indexOf(7); // -1
array.indexOf(9, 2); // 2
array.indexOf(2, -1); // -1
array.indexOf(2, -3); // 0
</pre>
</code></pre>
<h3 id="找出指定元素出现的所有位置">找出指定元素出现的所有位置</h3>
<pre class="brush: js">var indices = [];
<pre><code class="language-javascript">var indices = [];
var array = ['a', 'b', 'a', 'c', 'a', 'd'];
var element = 'a';
var idx = array.indexOf(element);
@@ -40,9 +40,9 @@ while (idx != -1) {
}
console.log(indices);
// [0, 2, 4]
</pre>
</code></pre>
<h3 id="判断一个元素是否在数组里,不在则更新数组">判断一个元素是否在数组里,不在则更新数组</h3>
<pre class="brush: js">function updateVegetablesCollection (veggies, veggie) {
<pre><code class="language-javascript">function updateVegetablesCollection (veggies, veggie) {
if (veggies.indexOf(veggie) === -1) {
veggies.push(veggie);
console.log('New veggies collection is : ' + veggies);
@@ -56,10 +56,10 @@ var veggies = ['potato', 'tomato', 'chillies', 'green-pepper'];
// New veggies collection is : potato,tomato,chillies,green-papper,spinach
updateVegetablesCollection(veggies, 'spinach');
// spinach already exists in the veggies collection.
updateVegetablesCollection(veggies, 'spinach'); </pre>
updateVegetablesCollection(veggies, 'spinach'); </code></pre>
<h2 id="Polyfill">Polyfill</h2>
<p><code>indexOf</code> 在ECMA-262 标准 的第5版中被加入但并非所有的浏览器都支持该方法。你可以在编写scripts时在其开头使用以下代码它能够允许你在没有本地支持的情况下使用indexOf方法。该算法符合ECMA-262第5版其中一项规定, 即假定 <a href="Reference/Global_Objects/TypeError" title="TypeError类型错误 对象用来表示值的类型非预期类型时发生的错误。"><code>TypeError</code></a><a href="Reference/Global_Objects/Math/abs" title="Math.abs(x) 函数返回指定数字 “x“ 的绝对值。如下:"><code>Math.abs</code></a> 呈现它们原有的值。</p>
<pre class="brush: js">// Production steps of ECMA-262, Edition 5, 15.4.4.14
<pre><code class="language-javascript">// Production steps of ECMA-262, Edition 5, 15.4.4.14
// Reference: http://es5.github.io/#x15.4.4.14
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(searchElement, fromIndex) {
@@ -124,7 +124,7 @@ if (!Array.prototype.indexOf) {
return -1;
};
}
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>