??? = ??? ?????.
??? +? ?? ???? ? ?????.
Operator =? JavaScript ??? ?? ???? ? ?????.
?? ??? +? ?? ??? ? ?????.
?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文網(wǎng)(php.cn)</title>
</head>
<body>
<p>點(diǎn)擊按鈕計(jì)算 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>
????? ???? ??? ???
JavaScript ?? ???
?? ???? ?? ??? ???? ? ?????. ?? ?/?? ? ??? ???? ??.
y=5? ?? ?? ???? ??? ?? ???? ?? ?????.
+
/ ??? | x=y/2 | x=2.5 | | %
??? ??(?? ??) | x=y%2 | x=1 | | ++
?? | x=++y | x=6 | | --
decreasing | x=--y | x=4 | |
| JavaScript ?? ??? | | ?? ??? JavaScript ??? ?? ???? ? ?????. | x=10 ? y=5? ?? ?? ???? ?? ???? ?????. =y
| x=5 | | += | x+=y
x=x+y | x=15 | | -= | x-=y
x=x-y | x= 5 | | *= | x*=y
x=x*y
x=50
/=
x/=y
x=x/y
x =2
%=x%=y | x=x%y | x=0 | |
+ ??? ???
+ ???? ??? ??? ??? ??? ??(??)?? ? ?????.
? ? ??? ??? ??? ???? ?? ?? + ???? ?????.
?
? ? ??? ??? ??? ???? ?? ?? + ???? ?????.
<!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>
????? ???? ??? ???
? ??? ??? ??? ????? ??? ???? ???. ??? ???? ??:
<!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>
????? ???? ??? ???.
?? ???? ??? ?????.
<!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>
????? ???? ??? ???.
???? ?? ??
? ?? ??? ???? ??? ?? ?????. ??? ???? ???? ???? ?????. ?:
Example
<!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>
Rule: ???? ??? ???? ??? ???? ? ????!
????? ???? ??? ???
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文網(wǎng)(php.cn)</title>
</head>
<body>
<p>點(diǎn)擊按鈕計(jì)算 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>
?? ????? ????? ? ????. ?? ???? ???? ????. ???? ? ??? ?? ?? ??????~
? ??? ??? ???? ???? ????.