一
<body> <p id="demo">单击按钮舍入与“2.5”最接近的整数</p> <button onclick="myFunction()">点击</button> <script> function myFunction(){ document.getElementById("demo").innerHTML=Math.round(2.5); }
<body> <p id="demo">点击按钮显示一个随机数</p> <button onclick="myFunction()">点击</button> <script> function myFunction(){ document.getElementById("demo").innerHTML=Math.random(); } </script> </body>
<body> <p id="demo">单击按钮返回5到10之间的最大值。</p> <button onclick="myFunction()">点击</button> <script> function myFunction(){ document.getElementById("demo").innerHTML=Math.max(5,10); } </script> </body>
<body> <p id="demo">单击按钮返回5到10之间最小的值。</p> <button onclick="myFunction()">点击</button> <script> function myFunction(){ document.getElementById("demo").innerHTML=Math.min(5,10); } </script> </body>
二.几个数学的script语句