我的脚本中有这个函数,但 Internet Explorer 抛出一个错误: “el objeto no acepta la propiedad o el metodo trunc”意思是“对象不接受属性或方法 chop ”
function minutesToString(a){
var hours = Math.trunc(a/60);
var minutes = a % 60;
return(hours +" hr "+ minutes + " m");
}
在 chrome、firefox 等上完美运行。
最佳答案
为 Math.trunc()
添加一个 polyfill。在使用 Math.trunc()
Math.trunc = Math.trunc || function(x) {
if (isNaN(x)) {
return NaN;
}
if (x > 0) {
return Math.floor(x);
}
return Math.ceil(x);
};
关于javascript - 该对象不接受属性或方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44576098/