JavaScript ?? ??
JavaScript Math(??) ??
Math(??) ??? ??? ???? ?? ??? ???? ????.
round() ?? ??:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <p id="demo">單擊按鈕舍入與“9.5”最接近的整數(shù)</p> <button onclick="myFunction()">點(diǎn)我</button> <script> function myFunction(){ document.getElementById("demo").innerHTML=Math.round(9.5); } </script> </body> </html>
random()? ???? 0? 1 ??? ??? ???? ??:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <p id="demo">點(diǎn)擊按鈕顯示一個(gè)隨機(jī)數(shù)</p> <button onclick="myFunction()">點(diǎn)我</button> <script> function myFunction(){ document.getElementById("demo").innerHTML=Math.random(); } </script> </body> </html>
max()? ???? ??? ? ?? ? ? ? ??? ???? ??. (ECMASCript v3 ???? ? ???? ??? ? ???????.) :
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <p id="demo">單擊按鈕返回5到10之間的最大值。</p> <button onclick="myFunction()">點(diǎn)我</button> <script> function myFunction(){ document.getElementById("demo").innerHTML=Math.max(5,10); } </script> </body> </html>
min()? ???? ??? ? ?? ? ? ?? ??? ???? ?????. (ECMASCript v3 ???? ? ????? ? ?? ????? ?????.)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <p id="demo">單擊按鈕返回5到10之間最小的值。</p> <button onclick="myFunction()">點(diǎn)我</button> <script> function myFunction(){ document.getElementById("demo").innerHTML=Math.min(5,10); } </script> </body> </html>
Math ??
Math(??) ??? ???? ?? ??? ???? ? ?????.
Math ??? ??? ?? ? ??? ??? ?????. ? ??? ???? ?? ??? ??? ????.
Math? ??/??? ??? ?? ??:
var x=Math.PI;
var y=Math.sqrt(16);
??: Math ??? ? ??? ???? ?? ??? ??? ????.
?? ?
JavaScript? Math ???? ???? ? ?? 8?? ?? ?? ?????.
?? Javascript ?? ?? ??? ??? ? ????.
Math.E
Math.PI
Math.SQRT2
Math .SQRT1_2
Math.LN2
Math.LN10
Math.LOG2E
Math.LOG10E
?? ???
Math ???? ??? ? ?? ?? ? ??? ?? ??(???)? ????. ) ??? ? ????.
?? ???? Math ??? round ???? ???? ??? ??????.
document.write(Math.round(4.7));
? ??? ??? ??? ????.
5
?? ???? Math ??? random() ???? ???? 0? 1 ??? ?? ?????. ??:
document.write(Math.random());
? ??? ??? ??? ????.
0.18346685613505542
?? ???? Math ??? Floor() ???? Random()? ???? ?????. 0?? 11 ??? ??? ??:
document.write(Math.floor(Math.random()*11));
? ??? ??? ??? ????.
9