We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
页面加载一段时间后再点击创建定时器的按钮,显示的结束时间与实际情况不符。
用于获取当前时间的实例 date 在页面加载时就已作为全局变量创建,并且之后无法更新,计时结束的时间均以页面加载的时刻为基准计算,导致出现错误。 可将 Date 实例的创建放在 updateTime 函数内,每次点击按钮就重新获取当前时间:
date
Date
updateTime
function updateTime(delta){ let currentTime = new Date().getTime(); left = left + parseInt(delta,0); end = currentTime + left*1000; leftTime.innerHTML = left; endTime.innerHTML =new Date(end).toLocaleTimeString(); }
位置 JavaScript30/29 - Countdown Timer/scripts-START.js Line 38 in 1b044bc end = date.getTime() + left*1000;
位置
JavaScript30/29 - Countdown Timer/scripts-START.js
Line 38 in 1b044bc
The text was updated successfully, but these errors were encountered:
No branches or pull requests
问题
页面加载一段时间后再点击创建定时器的按钮,显示的结束时间与实际情况不符。
解决
用于获取当前时间的实例
date
在页面加载时就已作为全局变量创建,并且之后无法更新,计时结束的时间均以页面加载的时刻为基准计算,导致出现错误。可将
Date
实例的创建放在updateTime
函数内,每次点击按钮就重新获取当前时间:The text was updated successfully, but these errors were encountered: