国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

JavaScript 運(yùn)算符

運(yùn)算子 = 用於賦值。

運(yùn)算子 + 用於加值。

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

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


實例

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>
<p>點(diǎn)擊按鈕計算 x 的值.</p>
<button onclick="myFunction()">點(diǎn)擊這里</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ù)運(yùn)算子

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

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

#運(yùn)算子描述範(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 賦值運(yùn)算子

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

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


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



用於字串的+ 運(yùn)算子

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

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

實例

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

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>
<p>點(diǎn)擊按鈕創(chuàng)建及增加字符串變量。</p>
<button onclick="myFunction()">點(diǎn)擊這里</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>點(diǎn)擊按鈕創(chuàng)建及增加字符串變量。</p>
<button onclick="myFunction()">點(diǎn)擊這里</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í)行程式嘗試


或把空格插入表達(dá)式中:

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>
<p>點(diǎn)擊按鈕創(chuàng)建及增加字符串變量。</p>
<button onclick="myFunction()">點(diǎn)擊這里</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ù)字進(jìn)行加法運(yùn)算

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

實例

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>
<p>點(diǎn)擊按鈕創(chuàng)建及增加字符串變量。</p>
<button onclick="myFunction()">點(diǎn)擊這里</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>點(diǎn)擊按鈕計算 x 的值.</p> <button onclick="myFunction()">點(diǎn)擊這里</button> <p id="demo"></p> <script> function myFunction() { y=5; z=2; x=y+z; document.getElementById("demo").innerHTML=x; } </script> </body> </html>
提交重置程式碼
    #符例子等價於#結(jié)果
    =
    ##x=5
    x*=yx=x*yx=50
    x/=y