亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

JavaScript 運算符

運算子 = 用於賦值。

運算子 + 用於加值。

運算子 = 用來為 JavaScript 變數(shù)賦值。

算術(shù)運算子 + 用來把值加起來。


實例

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>
<p>點擊按鈕計算 x 的值.</p>
<button onclick="myFunction()">點擊這里</button>
<p id="demo"></p>
<script>
function myFunction()
{
y=5;
z=2;
x=y+z;
document.getElementById("demo").innerHTML=x;
}
</script>
</body>
</html>

執(zhí)行程式嘗試


JavaScript 算術(shù)運算子

算術(shù)運算子用於執(zhí)行變數(shù)與/或值之間的算術(shù)運算。

給定?y=5,下面的表格解釋了這些算術(shù)運算子:

#運算子描述範(fàn)例結(jié)果
+加上x=y+2x=7
-x=y-2x=3
*x=y*2x=10
/x=y/2x=2.5
#%求餘數(shù)(保留整數(shù))x=y%2x=1
++##x=++y#x=6
--#1x=--yx=4

##JavaScript 賦值運算子

#賦值運算子用於為JavaScript 變數(shù)賦值。

給定?x=10?和?y=5,以下的表格解釋了賦值運算子:


##x=y?x=5+=x+=yx=x+yx=15-=x-=yx=x-y*=/=##x=x/yx=2%=x%=yx=x%yx=0



用於字串的+ 運算子

+ 運算子用於把文字值或字串變數(shù)加起來(連接起來)。

如需把兩個或多個字串變數(shù)連接起來,請使用 + 運算子。

實例

如需把兩個或多個字串變數(shù)連接起來,請使用+ 運算子:

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>
<p>點擊按鈕創(chuàng)建及增加字符串變量。</p>
<button onclick="myFunction()">點擊這里</button>
<p id="demo"></p>
<script>
function myFunction()
{
txt1="What a very";
txt2="nice day";
txt3=txt1+txt2;
document.getElementById("demo").innerHTML=txt3;
}
</script>
</body>
</html>

執(zhí)行程式試試看


要想在兩個字串之間增加空格,需要把空格插入一個字串之中:

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>
<p>點擊按鈕創(chuàng)建及增加字符串變量。</p>
<button onclick="myFunction()">點擊這里</button>
<p id="demo"></p>
<script>
function myFunction()
{
txt1="What a very ";
txt2="nice day";
txt3=txt1+txt2;
document.getElementById("demo").innerHTML=txt3;
}
</script>
</body>
</html>

執(zhí)行程式嘗試


或把空格插入表達式中:

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>
<p>點擊按鈕創(chuàng)建及增加字符串變量。</p>
<button onclick="myFunction()">點擊這里</button>
<p id="demo"></p>
<script>
function myFunction()
{
txt1="What a very";
txt2="nice day";
txt3=txt1+" "+txt2;
document.getElementById("demo").innerHTML=txt3;
}
</script>
</body>
</html>

執(zhí)行程式試試看


#字串和數(shù)字進行加法運算

兩個數(shù)字相加,傳回數(shù)字相加的和,如果數(shù)字與字串相加,傳回字串,如下實例:

實例

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>
<p>點擊按鈕創(chuàng)建及增加字符串變量。</p>
<button onclick="myFunction()">點擊這里</button>
<p id="demo"></p>
<script>
function myFunction()
{
var x=5+5;
var y="5"+5;
var z="Hello"+5;
var demoP=document.getElementById("demo");
demoP.innerHTML=x + "<br>" + y + "<br>" + z;
}
</script>
</body>
</html>

規(guī)則:如果把數(shù)字與字串相加,結(jié)果就會變成字串!

執(zhí)行程式嘗試



# 繼續(xù)學(xué)習(xí)
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <p>點擊按鈕計算 x 的值.</p> <button onclick="myFunction()">點擊這里</button> <p id="demo"></p> <script> function myFunction() { y=5; z=2; x=y+z; document.getElementById("demo").innerHTML=x; } </script> </body> </html>

      <pre id="idngi"><fieldset id="idngi"></fieldset></pre>

        <abbr id="idngi"><samp id="idngi"><form id="idngi"></form></samp></abbr>
        #符例子等價於#結(jié)果
        =
        ##x=5
        x*=yx=x*yx=50
        x/=y