多个if语句未触发

时间:2016-06-01 19:20:14

标签: javascript jquery

这不重复。

我正在尝试执行以下操作,也许有更好的方法:

如果值A小于1,则向上舍入。 例如,如果值为0.88,则舍入为1.这很容易:

var A = 0.88
if(a < 1 ) {
var A = Math.round(a);
document.getElementById("value").value = A;
}

但我还需要以下内容:

值A应舍入为15分钟增量。例如,如果值A为1小时3分钟,则应该舍入到1.15

如果值A为1小时18分钟,则应该舍入到1.30。

我试过了:

        diff = document.getElementById('test').value;

        if(diff < 1 ){
            var diff = Math.round(diff);
            document.getElementById("hours").value = diff;
        }else if(diff > 1 && diff < 1.24){
            var diff = 1.25;
            document.getElementById("hours").value = diff;
        }else if(diff > 1.25 && diff < 1.49){
            var diff = 1.50;
            document.getElementById("hours").value = diff;
        } else {

        }

但它不起作用......

0 个答案:

没有答案