【发布时间】:2020-08-26 15:24:06
【问题描述】:
此代码在 Google Chrome 中运行良好,但在 Internet Explorer 中无法运行。
它是用 JavaScript 编写并与 HTML 一起使用的计时器代码。
如果有人可以帮助控制台 Chrome 和 Internet Explorer 屏幕截图也附上。它们没有显示任何错误。
function makeTimer() {
// var endTime = new Date("29 April 2018 9:56:00 GMT+01:00");
var endTime = new Date("19 May 2020 17:30:00 GMT+05:00");
endTime = (Date.parse(endTime) / 1000);
var now = new Date();
now = (Date.parse(now) / 1000);
var timeLeft = endTime - now;
var days = Math.floor(timeLeft / 86400);
var hours = Math.floor((timeLeft - (days * 86400)) / 3600);
var minutes = Math.floor((timeLeft - (days * 86400) - (hours * 3600)) / 60);
var seconds = Math.floor((timeLeft - (days * 86400) - (hours * 3600) - (minutes * 60)));
if (hours < "10") {
hours = "0" + hours;
}
if (minutes < "10") {
minutes = "0" + minutes;
}
if (seconds < "10") {
seconds = "0" + seconds;
}
$("#days").html(days + "<span>Days</span>");
$("#hours").html(hours + "<span>Hours</span>");
$("#minutes").html(minutes + "<span>Minutes</span>");
$("#seconds").html(seconds + "<span>Seconds</span>");
}
setInterval(function() {
makeTimer();
}, 1000);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="d-inline-block py-3" id="timer">
<div class="d-inline-block px-3" id="days" style="border-right:1px solid white; color:#44cbe1"></div>
<div class="d-inline-block px-3" id="hours" style="border-right:1px solid white; color:#44cbe1"></div>
<div class="d-inline-block px-3" id="minutes" style="border-right:1px solid white; color:#44cbe1"></div>
<div class="d-inline-block px-3" id="seconds" style="color:#44cbe1"></div>
</div>
【问题讨论】:
-
显示没有错误的工作浏览器的屏幕截图是没有意义的...显示 IE 控制台的输出...
-
现在附上两张截图。
-
你已经看过这里了吗? stackoverflow.com/questions/13091523/…
-
错误是明确的,它表示您忘记在某处关闭标签(或其他)。我认为这与您的 JS 代码无关。 Chrome 会原谅一些类似的小错误,而 IE 不会。
是的,我设法关闭了所有标签,现在屏幕截图已更新。但错误仍然相同
标签: javascript html javascript-objects