同一页面上有多个倒计时

发布于 2024-10-07 04:15:20 字数 307 浏览 4 评论 0原文

我一直在使用这个脚本( http://www.dynamicdrive.com/dynamicindex6/dhtmlcount.htm< /a> ) 假期倒计时。但这次我需要在一页上有 2 个倒计时。我尝试创建 2 个不同的页面,每个页面包含一个脚本,并将它们包含到主页中,但这不起作用。

有人知道如何编辑它或有一个适用于此目的的脚本吗?我尝试编辑一些变量,但无法让它工作。

谢谢。

I have been using this script ( http://www.dynamicdrive.com/dynamicindex6/dhtmlcount.htm ) for countdown to vacations. But this time i need to have 2 countdowns on ONE page. I tried having 2 different pages with one script in each and include them to the main page, but that did not work.

Anyone know how to edit it or have a script that works for this purpose? I tried editing some of the variables but I were unable to get it to work.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里兽 2024-10-14 04:15:20

我编写了一个简单的倒计时构造函数,可以进一步帮助您。

function countDown(startTime, divid, the_event){
    var tdiv = document.getElementById(divid)
        ,start = parseInt(startTime.getTime(),10)
        ,the_event = the_event || startTime.toLocaleString()
        ,to;
    this.rewriteCounter = function(){
      var now = new Date().getTime()
          ,diff = Math.round((start - now)/1000);
      if (startTime > now)
      {
        tdiv.innerHTML = diff +' seconds untill ' + the_event;
      }
      else {clearInterval(to);}
    };
    this.rewriteCounter();
    to = setInterval(this.rewriteCounter,1000);
}

//usage
var count1 = new countDown(new Date('2010/12/11 10:44:59')
                           ,'counter1'
                           ,'tomorrow 10:45');
var count2 = new countDown(new Date('2010/12/25')
                           ,'counter2'
                           ,'first christmas day');

看看@jsfiddle

I have cooked up a simple countdown Constructor which may help you further.

function countDown(startTime, divid, the_event){
    var tdiv = document.getElementById(divid)
        ,start = parseInt(startTime.getTime(),10)
        ,the_event = the_event || startTime.toLocaleString()
        ,to;
    this.rewriteCounter = function(){
      var now = new Date().getTime()
          ,diff = Math.round((start - now)/1000);
      if (startTime > now)
      {
        tdiv.innerHTML = diff +' seconds untill ' + the_event;
      }
      else {clearInterval(to);}
    };
    this.rewriteCounter();
    to = setInterval(this.rewriteCounter,1000);
}

//usage
var count1 = new countDown(new Date('2010/12/11 10:44:59')
                           ,'counter1'
                           ,'tomorrow 10:45');
var count2 = new countDown(new Date('2010/12/25')
                           ,'counter2'
                           ,'first christmas day');

Check it out @jsfiddle

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文