mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-12-15 15:20:30 +08:00
语法高亮,滚动条美化,设置页面调整
This commit is contained in:
@@ -8,11 +8,11 @@
|
||||
<p>The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a class="external" href="https://github.com/mdn/interactive-examples" rel="noopener">https://github.com/mdn/interactive-examples</a> and send us a pull request.</p>
|
||||
</div>
|
||||
<h2 id="Syntax" name="Syntax">语法</h2>
|
||||
<pre class="syntaxbox">if (<em>condition</em>)
|
||||
<pre><code class="language-javascript">if (<em>condition</em>)
|
||||
<em>statement1</em>
|
||||
[else
|
||||
<em>statement2</em>]
|
||||
</pre>
|
||||
</code></pre>
|
||||
<dl>
|
||||
<dt><code>condition</code></dt>
|
||||
<dd>值为真或假的<a href="Guide/Expressions_and_Operators#Expressions">表达式</a></dd>
|
||||
@@ -37,7 +37,7 @@ else if (<em>condition3</em>)
|
||||
else
|
||||
<em>statementN</em>
|
||||
|
||||
</pre>
|
||||
</code></pre>
|
||||
<p>要看看它如何工作,可以调整下嵌套的缩进:</p>
|
||||
<pre class="eval">if (<em>condition1</em>)
|
||||
<em>statement1</em>
|
||||
@@ -47,47 +47,47 @@ else
|
||||
else
|
||||
if (<em>condition3</em>)
|
||||
...
|
||||
</pre>
|
||||
</code></pre>
|
||||
<p>要在一个从句中执行多条语句,可使用语句块(<code>{ ... }</code>)。通常情况下,一直使用语句块是个好习惯,特别是在涉及嵌套<code>if</code>语句的代码中:</p>
|
||||
<pre class="eval">if (<em>condition</em>) {
|
||||
<em>statements1</em>
|
||||
} else {
|
||||
<em>statements2</em>
|
||||
}
|
||||
</pre>
|
||||
</code></pre>
|
||||
<p>不要将原始布尔值的<code>true</code>和<code>false</code>与<a href="Reference/Global_Objects/Boolean" title="en/JavaScript/Reference/Global_Objects/Boolean">Boolean</a>对象的真或假混淆。任何一个值,只要它不是 <code>undefined</code><font face="Open Sans, Arial, sans-serif">、</font><code>null</code>、 <code>0</code><font face="Open Sans, Arial, sans-serif">、</font><code>NaN</code>或空字符串(<code>""</code>),那么无论是任何对象,即使是值为假的Boolean对象,在条件语句中都为真。例如:</p>
|
||||
<pre class="brush: js">var b = new Boolean(false);
|
||||
<pre><code class="language-javascript">var b = new Boolean(false);
|
||||
if (b) //表达式的值为true
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h2 id="Examples" name="Examples">示例</h2>
|
||||
<h3 id="Example:_Using_if...else" name="Example:_Using_if...else">使用 <code>if...else</code></h3>
|
||||
<pre class="brush: js">if (cipher_char === from_char) {
|
||||
<pre><code class="language-javascript">if (cipher_char === from_char) {
|
||||
result = result + to_char;
|
||||
x++;
|
||||
} else {
|
||||
result = result + clear_char;
|
||||
}
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="使用_else_if">使用 <code>else if</code></h3>
|
||||
<p>注意,Javascript中没有<code>elseif</code>语句。但可以使用<code>else</code>和<code>if</code>中间有空格的语句:</p>
|
||||
<pre class="brush: js">if (x > 5) {
|
||||
<pre><code class="language-javascript">if (x > 5) {
|
||||
/* do the right thing */
|
||||
} else if (x > 50) {
|
||||
/* do the right thing */
|
||||
} else {
|
||||
/* do the right thing */
|
||||
}</pre>
|
||||
}</code></pre>
|
||||
<h3 id="Example:_Assignment_within_the_conditional_expression" name="Example:_Assignment_within_the_conditional_expression">条件表达式中的赋值运算</h3>
|
||||
<p>建议不要在条件表达式中单纯的使用赋值运算,因为粗看下赋值运算的代码很容易让人误认为是等性比较。比如,不要使用下面示例的代码:</p>
|
||||
<pre class="brush: js example-bad">if (x = y) {
|
||||
<pre><code class="language-js example-bad">if (x = y) {
|
||||
/* do the right thing */
|
||||
}
|
||||
</pre>
|
||||
</code></pre>
|
||||
<p>如果你需要在条件表达式中使用赋值运算,用圆括号包裹赋值运算。例如:</p>
|
||||
<pre class="brush: js example-good">if ((x = y)) {
|
||||
<pre><code class="language-js example-good">if ((x = y)) {
|
||||
/* do the right thing */
|
||||
}
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h2 id="规范">规范</h2>
|
||||
<table class="standard-table">
|
||||
<tbody>
|
||||
|
||||
Reference in New Issue
Block a user