1
<p id="demo">单击按钮不保留小数位</p>
2
<button onclick="myFunction()">点我</button>
3
<script>
4
function myFunction() {
5
var num = 5.56789;
6
var x = document.getElementById("demo");
7
x.innerHTML = num.toFixed();
8
}
9
</script>
<p id="demo">单击按钮不保留小数位</p>
<button onclick="myFunction()">点我</button>
<script>
function myFunction() {
var num = 5.56789;
var x = document.getElementById("demo");
x.innerHTML = num.toFixed();
}
</script>