1 <div class="nlpz_sjdjs">剩余:<span>00</span>:<span>00</span>:<span>00</span></div> 2 3 <script type="text/javascript"> 4 var starttime = new Date("2018-03-09 15:44:00"); 5 function tt(){ 6 var nowtime = new Date(); 7 //alert(nowtime); 8 var time = starttime - nowtime; 9 var day = parseInt(time / 1000 / 60 / 60 / 24);//天 10 var hour = parseInt(time / 1000 / 60 / 60 % 24);//小时 11 var minute = parseInt(time / 1000 / 60 % 60);//分钟 12 var seconds = parseInt(time / 1000 % 60);//秒 13 14 if(hour<=0 && minute<=0 && seconds<=0){ 15 clearInterval(sj); 16 $('.nlpz_sjdjs').html("活动已结束"); 17 }else{ 18 $('.nlpz_sjdjs').html('剩余'+day+'天:'+'<span>'+hour+'</span>'+':'+'<span>'+minute+'</span>'+':'+'<span>'+seconds+'</span>'); 19 } 20 } 21 var sj = setInterval(function () {tt();}, 1000); 22 </script>
注意引入jquery