js 倒計時功能源碼

來源:互聯網
上載者:User

標籤:


<div class="time timers" rel="<?php echo date(‘m/d/Y‘, time()+24*3600)?>">                           <span class="ico_time"></span>                           <span class="data_title ">還剩<span class="data_pink pinkft"><span class="hours">7</span>時<span class="mins">46</span>分<span class="">33</span>秒</span>
                                                </span> </span>                         </div>


//以下是js代碼

 $(document).ready(function(){timing();});// 倒計時function timing(){    $(".timers").each(function(){        var endtime = new Date($(this).attr("rel")).getTime();        var nowtime = new Date();         var youtime = 0;               youtime = endtime - nowtime;         var seconds = youtime/1000;        var minutes = Math.floor(seconds/60);        var hours = Math.floor(minutes/60);        var CHour= hours % 24;        var CMinute= minutes % 60;        var CSecond= Math.floor(seconds%60);//"%"var MS=Math.floor(youtime) % 10;        if(endtime<=nowtime){            //$(this).html("已到期")//如果結束日期小於當前日期就提示到期啦        }else{            $(this).html("還剩<span class=‘pinkft data_pink‘><span class=‘hours‘>"+CHour+"</span>時<span class=‘mins‘>"+CMinute+"</span>分<span class=‘‘>"+CSecond+‘.‘+MS+"</span>秒</span>");                  if(CHour < 10){                $("#hours").text("0"+CHour);            }else{                $("#hours").text(CHour);            }             if(CMinute < 10){                $("#minute").text("0"+CMinute);            }else{                $("#minute").text(CMinute);            }             if(CSecond < 10){                $("#second").text(CSecond+‘.‘+MS);            }else{                $("#second").text(CSecond+‘.‘+MS);            }        }    });    setTimeout("timing()",100);}

js 倒計時功能源碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.