0

私は休暇へのカウントダウンにこのスクリプト(http://www.dynamicdrive.com/dynamicindex6/dhtmlcount.htm )を使用しています。しかし、今回は1ページに2つのカウントダウンが必要です。それぞれに1つのスクリプトを含む2つの異なるページを作成し、それらをメインページに含めようとしましたが、うまくいきませんでした。

誰かがそれを編集する方法を知っているか、この目的のために機能するスクリプトを持っていますか?いくつかの変数を編集しようとしましたが、機能させることができませんでした。

ありがとう。

4

1 に答える 1

1

さらに役立つかもしれない単純なカウントダウンコンストラクターを作成しました。

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でチェックしてください

于 2010-12-10T15:07:06.880 に答える