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

JavaScript 運(yùn)算符


運(yùn)算符 = 用于賦值。

運(yùn)算符 + 用于加值。


運(yùn)算符 = 用于給 JavaScript 變量賦值。

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

實(shí)例

<!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>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例


JavaScript 算術(shù)運(yùn)算符

加法:


實(shí)例

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>

<p>假設(shè) y=5,計算 x=y+2,并顯示結(jié)果。</p>
<button onclick="myFunction()">點(diǎn)擊這里</button>
<p id="demo"></p>
<script>
function myFunction(){
	var y=5;
	var x=y+2;
	var demoP=document.getElementById("demo")
	demoP.innerHTML="x=" + x;
}
</script>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

減法:

實(shí)例

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>

<p>設(shè)置 y=5, 計算出 x=y-2, 并輸出結(jié)果。</p>
<button onclick="myFunction()">點(diǎn)我</button>
<p id="demo"></p>
<script>
function myFunction()
{
	var y=5;
	var x=y-2;
	var demoP=document.getElementById("demo");
	demoP.innerHTML="x=" + x;
}
</script>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

乘法:

實(shí)例

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>

<p>設(shè)置 y=5, 計算出 x=y*2, 并輸出結(jié)果。</p>
<button onclick="myFunction()">點(diǎn)我</button>
<p id="demo"></p>
<script>
function myFunction()
{
	var y=5;
	var x=y*2;
	var demoP=document.getElementById("demo")
	demoP.innerHTML="x=" + x;
}
</script>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

除法:

實(shí)例

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>

<p>設(shè)置 y=5, 計算 x=y/2, 并輸出結(jié)果。</p>
<button onclick="myFunction()">點(diǎn)我</button>
<p id="demo"></p>
<script>
function myFunction()
{
	var y=5;
	var x=y/2;
	var demoP=document.getElementById("demo")
	demoP.innerHTML="x=" + x;
}
</script>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

取模(余數(shù))

實(shí)例

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>

<p>設(shè)置 y=5, 計算出 x=y%2, 并顯示結(jié)果。</p>
<button onclick="myFunction()">點(diǎn)我</button>
<p id="demo"></p>
<script>
function myFunction()
{
	var y=5;
	var x=y%2;
	var demoP=document.getElementById("demo")
	demoP.innerHTML="x=" + x;
}
</script>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

自增:

實(shí)例

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>

<p>設(shè)置 y=5, 計算出 x=++y, 并顯示結(jié)果。</p>
<button onclick="myFunction()">點(diǎn)我</button>
<p id="demo"></p>
<script>
function myFunction()
{
	var y=5;
	var x=++y;
	var demoP=document.getElementById("demo")
	demoP.innerHTML="x=" + x + ", y=" + y;
}
</script>
<p><strong>注意:</strong>兩個值 x 和 y 都受到影響。</p>
	
</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

實(shí)例

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>

<p>設(shè)置 y=5, 計算出 x=y++, 并顯示結(jié)果。</p>
<button onclick="myFunction()">點(diǎn)我</button>
<p id="demo"></p>
<script>
function myFunction()
{
	var y=5;
	var x=y++;
	var demoP=document.getElementById("demo")
	demoP.innerHTML="x=" + x + ", y=" + y;
}
</script>
<p><strong>注意:</strong> x 和 y 兩個值都受到影響。</p>
	
</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

自減:

實(shí)例

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>

<p>設(shè)置 y=5, 計算出 x=--y, 并顯示結(jié)果。</p>
<button onclick="myFunction()">點(diǎn)我</button>
<p id="demo"></p>
<script>
function myFunction()
{
	var y=5;
	var x=--y;
	var demoP=document.getElementById("demo")
	demoP.innerHTML="x=" + x + ", y=" + y;
}
</script>
<p><strong>注意:</strong> x 和 y 兩個值都會被影響。</p>
	
</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

實(shí)例

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>

<p>設(shè)置 y=5, 計算出 x=y--, 并顯示結(jié)果。</p>
<button onclick="myFunction()">點(diǎn)我</button>
<p id="demo"></p>
<script>
function myFunction()
{
	var y=5;
	var x=y--;
	var demoP=document.getElementById("demo")
	demoP.innerHTML="x=" + x + ", y=" + y;
}
</script>
<p><strong>注意:</strong>x 和 y 兩個值都會受到影響。</p>
	
</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

JavaScript 賦值運(yùn)算符

賦值運(yùn)算符用于給 JavaScript 變量賦值。

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

=:

實(shí)例

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>

<p>設(shè)置 x=10 和 y=5, 計算 x=y, 并顯示結(jié)果。</p>
<button onclick="myFunction()">點(diǎn)我</button>
<p id="demo"></p>
<script>
function myFunction()
{
	var x=10;
	var y=5;
	x=y;
	var demoP=document.getElementById("demo")
	demoP.innerHTML="x=" + x;
}
</script>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

+=:

實(shí)例

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>

<p>設(shè)置 x=10 和 y=5, 計算 x+=y, 并顯示結(jié)果。</p>
<button onclick="myFunction()">點(diǎn)我</button>
<p id="demo"></p>
<script>
function myFunction()
{
	var x=10;
	var y=5;
	x+=y;
	var demoP=document.getElementById("demo")
	demoP.innerHTML="x=" + x;
}
</script>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

-=:

實(shí)例

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>

<p>設(shè)置 x=10 和 y=5, 計算 x-=y, 并顯示結(jié)果。</p>
<button onclick="myFunction()">點(diǎn)我</button>
<p id="demo"></p>
<script>
function myFunction()
{
	var x=10;
	var y=5;
	x-=y;
	var demoP=document.getElementById("demo")
	demoP.innerHTML="x=" + x;
}
</script>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

*=:

實(shí)例

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>

<p>設(shè)置 x=10 和 y=5, 計算 x*=y, 并顯示結(jié)果。</p>
<button onclick="myFunction()">點(diǎn)我</button>
<p id="demo"></p>
<script>
function myFunction()
{
	var x=10;
	var y=5;
	x*=y;
	var demoP=document.getElementById("demo")
	demoP.innerHTML="x=" + x;
}
</script>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

/=:

實(shí)例

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>

<p>設(shè)置 x=10 和 y=5, 計算 x/=y, 并顯示結(jié)果。</p>
<button onclick="myFunction()">點(diǎn)我</button>
<p id="demo"></p>
<script>
function myFunction()
{
	var x=10;
	var y=5;
	x/=y;
	var demoP=document.getElementById("demo");
	demoP.innerHTML="x=" + x;
}
</script>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

%=:

實(shí)例

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>

<p>設(shè)置 x=10 和 y=5, 計算 x%=y, 并顯示結(jié)果。</p>
<button onclick="myFunction()">點(diǎn)我</button>
<p id="demo"></p>
<script>
function myFunction()
{
	var x=10;
	var y=5;
	x%=y;
	var demoP=document.getElementById("demo")
	demoP.innerHTML="x=" + x;
}
</script>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例


用于字符串的 + 運(yùn)算符

+ 運(yùn)算符用于把文本值或字符串變量加起來(連接起來)。

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

實(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()
{
	txt1="What a very";
	txt2="nice day";
	txt3=txt1+txt2;
	document.getElementById("demo").innerHTML=txt3;
}
</script>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎ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()
{
	txt1="What a very ";
	txt2="nice day";
	txt3=txt1+txt2;
	document.getElementById("demo").innerHTML=txt3;
}
</script>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

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

實(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()
{
	txt1="What a very";
	txt2="nice day";
	txt3=txt1+" "+txt2;
	document.getElementById("demo").innerHTML=txt3;
}
</script>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例


對字符串和數(shù)字進(jìn)行加法運(yùn)算

兩個數(shù)字相加,返回數(shù)字相加的和,如果數(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>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

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