倒计时:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript"> window.onload=function(){ showTime(); //调用showTim function checkTime(i){ if(i<10){ i="0"+i; } return i; } //重复秒数,让秒数动 function showTime() { var myDate=new Date(); var year=myDate.getFullYear(); var month=myDate.getMonth()+1; var day=myDate.getDate(); var d=myDate.getDate(); var h=myDate.getHours(); var m=myDate.getMinutes(); var s=myDate.getSeconds(); m = checkTime(m); s = checkTime(s); var weekday=new Array(7) weekday[0]='星期一' weekday[1]='星期二' weekday[2]='星期三' weekday[3]='星期四' weekday[4]='星期五' weekday[4]='星期六' weekday[6]='星期日' document.getElementById('show').innerHTML=year+'年'+month+'月'+day+'日'+weekday[d] +h+':'+m+':'+s; setTimeout(showTime,500) } } </script> </head> <body> <div id="show">时间显示</div> </body> </html>
限时购:
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>团购——限时抢</title> <style> @charset "UTF-8"; /* CSS Document */ div,img{ margin:0; padding:0; border:0; } .content3{ background:url(http://img.mukewang.com/534d13940001063d12000398.jpg) no-repeat; 1200px; height:398px; margin:0 auto; position:relative; } .time{ position:absolute; top:122px; left:46%; line-height:22px; font-size:14px; } </style> </head> <body> <div class="content3"> <div class="time">还剩 <span id="LeftTime"></span></div> </div> <script> function FreshTime() { var endtime=new Date("2017/2/15,12:20:12");//结束时间 var nowtime = new Date();//当前时间 var lefttime= (endtime.getTime() - nowtime.getTime())/1000; d= parseInt(lefttime/(60*60*24)) ; h= parseInt(lefttime/(60*60)%24) ; m= parseInt(lefttime/60%60) ; s= parseInt(lefttime%60) ; document.getElementById("LeftTime").innerHTML=d+"天"+h+"小时"+m+"分"+s+"秒"; if(lefttime<=0){ document.getElementById("LeftTime").innerHTML="团购已结束"; clearInterval(sh); } } FreshTime() var sh; sh= setInterval(FreshTime,300); </script> </body> </html>