一つのページに複数のカウントダウンjsコードがあります.


もっと読む
大まかに整理してください
解決の需要:
1.複数のページのカウントダウンを解決する2.サーバと時間を確認する3.ページカウントダウンが完了したら、まずサーバとカウントダウンが完了したかどうかを確認し、終了したらコールバック関数を呼び出します.そうでなければカウントダウンを続けます.
カウントダウンJs関数:

/**
	 *      
	 * @param ids   id
	 * @param ifinvest     
	 * */
	function counts(ids,ifinvest){
		var interval,a=0,time,startt,tenderid;
		this.startcout=function(){
			startt = document.getElementById(ids).getAttribute("date-start");
			var nowtime = document.getElementById(ids).getAttribute("date-now");
			tenderid = document.getElementById(ids).getAttribute("tender-id");
			time = this.getSecond(startt,nowtime);
			if (!interval)
	            interval = setInterval(this.go, 1000);
		}
		this.go=function(){
			a++;
			--time;
			var str="";
			//--------------
			d = Math.floor(time / 86400),   
			h = Math.floor((time % 86400) / 3600),   
			m = Math.floor(((time % 86400) % 3600) / 60),   
			s = Math.floor(((time % 86400) % 3600) % 60); 
			
			if(a==300 || time <= 0){// 300         
				a=0;
				$.ajax({//        
					url : "web/getsysdatetime.do",
					type : "post",
					dataType : 'json',
					success : function(data) {
						var oStartDate = js_patch_getdate(startt+"");
						var oNowDate = js_patch_getdate(data+"");
						var startTime = oStartDate.getTime();
						var nowTime = oNowDate.getTime();
						time = (startTime-nowTime)>0?(startTime-nowTime)/1000:0;
						if(time<=0){
							clearInterval(interval);//     
							ifinvest.starts();//       
						}
					},
					error:function(XMLHttpRequest, textStatus, errorThrown){
						clearInterval(interval);//     
					}
				});
			}
			if (time>0){ 
				str = ""+js_patch_fillZero(d, 2)+" "+js_patch_fillZero(h, 2)+" "+js_patch_fillZero(m, 2)+" "+js_patch_fillZero(s, 2)+" ";
			}else{
				str = "00 00 00 00 ";
			}
			document.getElementById(ids).innerHTML = str;
		}
		this.getSecond=function(startdate,nowdate) {
			var oStartDate = js_patch_getdate(startdate+"");
			var oNowDate = js_patch_getdate(nowdate+"");
			
			var startTime = oStartDate.getTime();
			var nowTime = oNowDate.getTime();

			var second = (startTime-nowTime)>0?(startTime-nowTime)/1000:0;
			return second;
		}
	}
	
	/**
	 *          ( :20150415092645)   js Date  
	 *   Date        
	 * */
	function js_patch_getdate(stime) {
		var datetime = new Date(
				parseFloat(stime.substr(0, 4)),
				parseFloat(stime.substr(4, 2) - 1),
				parseFloat(stime.substr(6, 2)),
				parseFloat(stime.substr(8, 2)),
				parseFloat(stime.substr(10, 2)),
				parseFloat(stime.substr(12, 2)));
		return datetime;
	}
	/**
	 *    
	 * */
	function js_patch_fillZero(num, digit) {
		var str = '' + num;
		while (str.length < digit) {
			str = '0' + str;
		}
		return str;
	}
HTML:

00 00 00 00
呼び出し:

//     $(document).ready(function() {}); 
if(document.getElementById("timer0")!=null){
		var ifstarts = new if_startinvest("timer0", document.getElementById("timer0").getAttribute("tender-id"));
		var counts_1 = new counts("timer0",ifstarts);
		counts_1.startcout();
	}