本文實例講述了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程序設計有所幫助。
新聞熱點
疑難解答