html javascript 实现 + -小数点2位
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;">
<title>html动态实现加减,保留小数点2位</title>
<style type="text/css">
.div input{
width: 40px;
text-align: center;
}
</style>
<script type="text/javascript">
function add() {
var num = document.getElementById("num");
num.value=(parseFloat(num.value)+0.01).toFixed(2);
}
function minus() {
var num = document.getElementById("num");
num.value=(parseFloat(num.value)-0.01).toFixed(2);
}
</script>
</head>
<body>
<div class="div">
<input type="button" value="-" onclick="minus()">
<input type="text" id="num" value="0">
<input type="button" value="+" onclick="add()" >
</div>
</body>
</html>