Home > Article > Web Front-end > Imitation Taobao transaction countdown effect implemented by JS_javascript skills
The example in this article describes the imitation Taobao transaction countdown effect implemented by JS. Share it with everyone for your reference, the details are as follows:
<script type="text/javascript"> var StartTime = new Date("2015/11/11 12:34:03"); document.write("订购时间: " + StartTime.toLocaleDateString() + StartTime.toLocaleTimeString() + "<br/>"); var CurrentTime = new Date(); document.write("当前时间: " + CurrentTime.toLocaleDateString() + CurrentTime.toLocaleTimeString() + "<br/>"); var EndTime=StartTime.getTime() + 15*24*60*60*1000;//约定订购时间15天后关闭交易 EndTime = new Date(EndTime); document.write("结束时间: " + EndTime.toLocaleDateString() + EndTime.toLocaleTimeString() + "<br/>"); var TempTime = StartTime; var nMS,nD,nH,nM,nS; function ShowCloseTime(){ var oDate = new Date(); nMS=EndTime-oDate ; nD=Math.floor(nMS/(1000*60*60*24)); nH=Math.floor(nMS/(1000*60*60)) % 24 ; nM=Math.floor(nMS/(1000*60)) % 60; nS=Math.floor(nMS/1000) % 60; document.getElementById("CloseTime").innerHTML = ("您还有" + nD + "天" + nH + "小时" + nM + "分" + nS + "秒完成交易"); if (nS<0 || nM<0 || nH<0 || nD<0) { document.getElementById("CloseTime").innerHTML = "交易因超过15天,已被系统自动关闭" clearInterval(CloseTimer); } } var CloseTimer = window.setInterval("ShowCloseTime()",1000) </script> <div id="CloseTime"></div>
I hope this article will be helpful to everyone in JavaScript programming.