javascript - 如何在这个倒计时脚本中添加天数,使其变成DD-HH-MM-SS?

标签 javascript jquery countdown

我在 jQuery 中有这个脚本:

// Auction countdown script
$(function () {

var remaining = $("#countdown").text(),
    regex = /\d{2}/g,
    matches = remaining.match(regex),
    hours = matches[0],
    minutes = matches[1],
    seconds = matches[2],
    remainingDate = new Date();

remainingDate.setHours(hours);
remainingDate.setMinutes(minutes);
remainingDate.setSeconds(seconds);

var intvl = setInterval(function () {
    var totalMs = remainingDate.getTime(),
        hours, minutes, seconds;

remainingDate.setTime(totalMs - 1000);

hours = remainingDate.getHours();
minutes = remainingDate.getMinutes();
seconds = remainingDate.getSeconds();

if (hours === 0 && minutes === 0 && seconds === 0) {
    alert('done');
}

$("#countdown").text(
    (hours >= 10 ? hours : "0" + hours) + ":" +
    (minutes >= 10 ? minutes : "0" + minutes)  + ":" +
    (seconds >= 10 ? seconds : "0" + seconds));

}, 1000);

});

现在,这需要一个字符串并为其进行 HHMMSS 倒计时。我希望它是 DDHHMMSS,但我似乎无法让它工作。谁能指出我正确的方向?

谢谢!

最佳答案

如果您想自己创建倒计时功能,请引用以下链接以构建正确的逻辑:

http://stuntsnippets.com/javascript-countdown/

http://www.hashemian.com/tools/javascript-countdown.htm

最好使用下面的 jQuery 插件

http://www.littlewebthings.com/projects/countdown/

http://keith-wood.name/countdown.html

希望对你有帮助

一切尽善尽美

关于javascript - 如何在这个倒计时脚本中添加天数,使其变成DD-HH-MM-SS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11758744/

相关文章:

javascript - 无法获取远程: true to work with link_to

javascript - `setState` 未与UI同步

jquery - jquery lavalamp 的问题

php - 如何使用计时器运行 php 脚本?

php - 跨多个页面的倒计时变量

javascript - HTML5 Canvas - 绘制重叠的多边形

javascript - 带有双星号的正则表达式 javascript

javascript - 调整浏览器窗口大小时 toggleClass 触发两次

jquery - 使用 jquery 根据下拉列表中选定的选项显示表行

javascript - 未捕获的类型错误 : Cannot set property 'innerText' of null - For Countdown Script