1
<p id="demo">单击按钮将不同的数值转换成最接近的整数</p>
2
<button onclick="myFunction()">点我</button>
3
<script>
4
function myFunction() {
5
var a = Math.round(2.60);
6
var b = Math.round(2.50);
7
var c = Math.round(2.49);
8
var d = Math.round(-2.60);
9
var e = Math.round(-2.50);
10
var f = Math.round(-2.49);
11
var x = document.getElementById("demo");
12
x.innerHTML = a + "<br>" + b + "<br>" + c + "<br>" + d + "<br>" + e + "<br>" + f;
13
}
14
</script>