编辑下面的代码:【加编码】
<html> <body> <p id="demo">Click the button to round different numbers to the nearest integer.</p> <button onclick="myFunction()">Try it</button> <script> function myFunction() { var a=Math.round(2.60); var b=Math.round(2.50); var c=Math.round(2.49); var d=Math.round(-2.60); var e=Math.round(-2.50); var f=Math.round(-2.49); var x=document.getElementById("demo"); x.innerHTML=a + "<br>" + b + "<br>" + c + "<br>" + d + "<br>" + e + "<br>" + f; } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂