gpt4 book ai didi

javascript - IE浏览器不支持Math.trunc()

转载 作者:行者123 更新时间:2023-12-02 21:39:28 26 4
gpt4 key购买 nike

下面的代码在 Chrome 中运行良好,但在 IE 浏览器中我看到以下控制台错误:

object does not support property or method 'trunc'

代码:

var Days = (new Date(date1) - new Date(date2)) / 50;
if (Math.trunc(Days) > 45)) {
alert("it should be less than 45 days");
}

最佳答案

MDN 声明 IE 不支持

Math.trunc,请阅读 here .

您可以使用 polifylls:

if (!Math.trunc) {
Math.trunc = function (v) {
return v < 0 ? Math.ceil(v) : Math.floor(v);
};
}

希望能够澄清。

关于javascript - IE浏览器不支持Math.trunc(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60402658/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com