$(".editor-number__plus").click(function() {
var n = (Math.round(parseFloat($(this).siblings("input").val())*10)/10)
n = n + 0.1
$(this).siblings("input").val(n)
})
初始值为10,使用以上代码点击按钮打印或显示出来的数值是:
10.1
10.2
10.299999999999999
10.4
10.5
10.6
10.7
10.799999999999999
10.9
11
11.1
11.2
11.299999999999999
11.4
11.5
11.6
11.7
11.799999999999999
11.9
12
12.1
12.2
12.299999999999999
12.4
12.5
12.6
12.7
12.799999999999999
请教该如何解决?
PHPz2017-04-10 16:33:06
$(".editor-number__plus").click(function() {
var n = Math.round(parseFloat($(this).siblings("input").val())*10)
var m = n + 1
$(this).siblings("input").val(m/10)
})
巴扎黑2017-04-10 16:33:06
$(".editor-number__plus").click(function() {
var n = (Math.round(parseFloat($(this).siblings("input").val())*10)/10);
n = n + 0.1;
$(this).siblings("input").val(n.toFixed(1));
})
OR
$(".editor-number__plus").click(function() {
var n = (Math.round(parseFloat($(this).siblings("input").val())*10));
n = (n+1)/10;
$(this).siblings("input").val(n)
})