gpt4 book ai didi

JavaScript/jQuery 倒计时

转载 作者:搜寻专家 更新时间:2023-11-01 04:47:53 27 4
gpt4 key购买 nike

我想要完成的是实时更新的倒计时...像这样:

6 天(只是几天)

12 小时(1 天内的几个小时)

59 分钟(1 小时内仅几分钟)

59 秒(1 分钟内的几秒)

实现此目的的最佳方法?

最佳答案

您可以在 http://jsfiddle.net/gaby/QH6X8/79/ 找到一个工作示例

var end = new Date('15 Dec 2010');

var _second = 1000;
var _minute = _second * 60;
var _hour = _minute * 60;
var _day = _hour *24

var timer;

function showRemaining()
{
var now = new Date();
var distance = end - now;
if (distance < 0 ) {
// handle expiry here..
clearInterval( timer ); // stop the timer from continuing ..
alert('Expired'); // alert a message that the timer has expired..
}
var days = Math.floor(distance / _day);
var hours = Math.floor( (distance % _day ) / _hour );
var minutes = Math.floor( (distance % _hour) / _minute );
var seconds = Math.floor( (distance % _minute) / _second );

var countdownElement = document.getElementById('countdown');
countdownElement.innerHTML = 'Days: ' + days + '<br />';
countdownElement.innerHTML += 'Hours: ' + hours+ '<br />';
countdownElement.innerHTML += 'Minutes: ' + minutes+ '<br />';
countdownElement.innerHTML += 'Seconds: ' + seconds+ '<br />';
}

timer = setInterval(showRemaining, 1000);

关于JavaScript/jQuery 倒计时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4150113/

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