カウントダウンjavascript
3739 ワード
<span style="color: #0000ff;">var</span> serverTime = <?php echo time();?> * 1000<span style="color: #000000;">;
</span><span style="color: #0000ff;">var</span> gotobuy=0,gotopay=0<span style="color: #000000;">;
</span><span style="color: #0000ff;">var</span> timeout=<span style="color: #0000ff;">null</span><span style="color: #000000;">;
$(</span><span style="color: #0000ff;">function</span><span style="color: #000000;">(){
</span><span style="color: #0000ff;">var</span> dateTime = <span style="color: #0000ff;">new</span><span style="color: #000000;"> Date();
</span><span style="color: #0000ff;">var</span> difference = dateTime.getTime() -<span style="color: #000000;"> serverTime;
timeout </span>= setInterval(<span style="color: #0000ff;">function</span><span style="color: #000000;">(){
$(</span>".endtime").each(<span style="color: #0000ff;">function</span><span style="color: #000000;">(){
</span><span style="color: #0000ff;">var</span> obj = $(<span style="color: #0000ff;">this</span><span style="color: #000000;">);
</span><span style="color: #0000ff;">var</span> endTime = <span style="color: #0000ff;">new</span> Date(parseInt(obj.attr('value')) * 1000<span style="color: #000000;">);
</span><span style="color: #0000ff;">var</span> nowTime = <span style="color: #0000ff;">new</span><span style="color: #000000;"> Date();
</span><span style="color: #0000ff;">var</span> nMS=endTime.getTime() - nowTime.getTime() +<span style="color: #000000;"> difference;
</span><span style="color: #0000ff;">var</span> myD=Math.floor(nMS/(1000 * 60 * 60 * 24)); //
<span style="color: #0000ff;">var</span> myH=Math.floor(nMS/(1000*60*60)) % 24; //
<span style="color: #0000ff;">var</span> myM=Math.floor(nMS/(1000*60)) % 60; //
<span style="color: #0000ff;">var</span> myS=Math.floor(nMS/1000) % 60; //
<span style="color: #0000ff;">var</span> myMS=Math.floor(nMS/100) % 10; //
<span style="color: #0000ff;">if</span>(myD>= 0<span style="color: #000000;">){
</span><span style="color: #0000ff;">var</span> str = (myD>0?'<span>'+myD+'</span> ':'')+'<span>'+myH+'</span> <span>'+myM+'</span> <span>'+myS+'</span> <span>'+myMS+'</span>'<span style="color: #000000;">;
// </span><span style="color: #000000;">
}</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{<br> //
window.clearInterval(timeout);
</span><span style="color: #0000ff;">var</span> str = '<span>0</span> <span>0</span> <span>0</span> '<span style="color: #000000;">;
</span><span style="color: #000000;">
}
obj.html(str);
});
}, </span>100<span style="color: #000000;">);
});</span>