字节跳动Tiktok团队北上广深杭急招前后端开发,绿色内推邮箱:sunmaoyu@bytedance.com

JS倒计时

<!--倒计时脚本-->
					<script type="text/javascript">
					var CID = "endtime";

					if(window.CID != null)
					{
						var dTime = document.getElementById(CID).innerText;
						var iTime = dTime*24*3600;
						var Account;
						
						RemainTime();
					}
					function RemainTime()
					{
						var iDay,iHour,iMinute,iSecond;
						var sDay="",sHour="",sMinute="",sSecond="",sTime="";
						if (iTime >= 0)
						{
							iDay = parseInt(iTime/24/3600);
							if (iDay > 0)
							{
								sDay = iDay + "天";
							}
							iHour = parseInt((iTime/3600)%24);
							if (iHour > 0){
								sHour = iHour + "小时";
							}
							iMinute = parseInt((iTime/60)%60);
							if (iMinute > 0){
								sMinute = iMinute + "分钟";
							}
							iSecond = parseInt(iTime%60);
							if (iSecond >= 0){
								sSecond = iSecond + "秒";
							}
							if ((sDay=="")&&(sHour=="")){
								sTime="<span style='color:darkorange'>" + sMinute+sSecond + "</font>";
							}
							else
							{
								sTime=sDay+sHour+sMinute+sSecond;
							}
							if(iTime==0){
								clearTimeout(Account);
								  sTime="<span style='color:green'>!</span>";
							}
							else
							{
								Account = setTimeout("RemainTime()",1000);
							}
							iTime=iTime-1;
						}
						else
						{
								sTime="<span style='color:red'>倒计时结束!</span>";
						}
						document.getElementById(CID).innerHTML = sTime;
					}

					</script> <!--倒计时脚本end-->

posted @ 2014-04-22 17:19  冒雨ing  阅读(171)  评论(0编辑  收藏  举报