js 60秒倒計時

function test()
{
	var sendTime = new Date().getTime();
	var testcount = 0;
	var countdown = 0;
	var validInterval = 59;
	var sendTime = new Date().getTime();
	
	countdown = setInterval(test1, 1000);
	
	function test1()
	{
		testcount++;
		console.info(testcount);
		console.info(countdown);
		var currentTime = new Date().getTime();
		var count = Math.floor(validInterval - (currentTime - sendTime)/1000); 
		console.info(count +1+ "s後重發");
		
		if(testcount == 3)
			window.clearInterval(countdown);
	}
}


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章