JavaScript的Math对象带有一个max函数用于获取两个数字的较大数,下面的代码详细演示了max的用法
<!DOCTYPE html> <html> <body> <p id="demo">Click the button to return the highest number of 5 and 10.</p> <button onclick="myFunction()">Try it</button> <script> function myFunction() { document.getElementById("demo").innerHTML=Math.max(5,10); } </script> </body> </html>