倒计时器在 Chrome/Safari 上无法正确呈现,但在 Firefox 上可以正常呈现
function countDownRound() {
if(myRoundTimeRemaining >= 0){
var secs = myRoundTimeRemaining;
if(secs < 10)
{
secs = "0" + secs;
}
$("#countdown").html(':'+secs);
CountdownTimer = setTimeout(countDownRound, 1000);
myRoundTimeRemaining--;
}
else{
$("#countdown").html('');
}
}
上面的代码在 Firefox 上执行了预期的操作。每秒,“倒计时”元素中都会显示一个递减的数字。
在 Safari 和 Chrome 上,代码运行正常,但屏幕上的元素没有改变。如果发生其他情况(例如调整浏览器窗口大小),元素会同时正确更新。
这看起来像是某种优化或基于线程的问题,但我找不到解决方案。
function countDownRound() {
if(myRoundTimeRemaining >= 0){
var secs = myRoundTimeRemaining;
if(secs < 10)
{
secs = "0" + secs;
}
$("#countdown").html(':'+secs);
CountdownTimer = setTimeout(countDownRound, 1000);
myRoundTimeRemaining--;
}
else{
$("#countdown").html('');
}
}
The code above does what's expected, on Firefox. Every second a decreasing number is displayed in the "countdown" element.
On Safari and Chrome, the code runs properly, but the on-screen element does not change. If something else happens (such as resizing the browser window) the elements update properly while.
This looks like some kind of optimization or thread-based problem, but I can't find a solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 Chrome、Safari 和 Firefox 上也能正常工作。
也许在这种情况下,您不需要使用 html 标签来显示结果,text() 可能比 html() 效果更好。
尝试使用
html() 代替。
OBS:看来操作系统的一些不稳定也会影响浏览器渲染。有人可以证实或否认这一点吗?
Works fine for me too on Chrome, Safari and Firefox.
Perhaps in this case that you don`t need to use html tags to display your result, text() may work better than html().
Try using
instead html().
OBS: Seems that some kids of instability on your operacional system can also affects browser rendering. Could someone please confirm or deny this?