JavaScript使用Max函数返回两个数字中较大数的方法
本文实例讲述了JavaScript使用Max函数返回两个数字中较大数的方法。分享给大家供大家参考。具体如下:
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>运行结果输出:10
希望本文所述对大家的javascript程序设计有所帮助。
相关推荐
lupeng 2020-11-14
sjcheck 2020-11-10
meylovezn 2020-08-28
owhile 2020-08-18
Francismingren 2020-08-17
pythonclass 2020-07-29
sunzhihaofuture 2020-07-19
爱读书的旅行者 2020-07-07
行吟阁 2020-07-05
tianqi 2020-07-05
行吟阁 2020-07-04
冰蝶 2020-07-04
lyg0 2020-07-04
owhile 2020-07-04
opspider 2020-06-28
lengyu0 2020-06-28
tianqi 2020-06-21
dadaooxx 2020-06-16