<head/>
<script type="text/javascript">
//var maxtime = 3600;//秒数
//var maxtime = document.getElementById("timer").innerHTML;
//var maxtime = document.getElementById("a").value;
var maxtime;
function CountDown(){
maxtime = document.getElementById("timer").innerHTML;
//alert(maxtime);
if(maxtime>=0){
days = Math.floor(maxtime/(3600*24));
hours = Math.floor((maxtime-days*3600*24)/3600);
minutes = Math.floor(((maxtime-days*3600*24)-hours*3600)/60);
seconds = Math.floor(maxtime%60);
msg = "倒计时:"+days+"天"+hours+"时"+minutes+"分"+seconds+"秒";//动态显示剩余时间。
document.all["timer"].innerHTML=msg;
--maxtime;
}
else{
clearInterval(timer);
document.all["timer"].innerHTML='不好意思,已经过期了,下次早来吧';
}
}
timer = setInterval("CountDown()",1000);
</script>
<body>
团购页面 <br>
<div id=timer>188888</div>
</c:forEach>
</body>
</html>
------解决方案--------------------
var maxtime = 0;
var boo= false;
function CountDown(){
if(boo==false){
maxtime=document.getElementById("timer").innerHTML;
boo=true;
}
if(maxtime>0){
days = Math.floor(maxtime/(3600*24));
hours = Math.floor((maxtime-days*3600*24)/3600);
minutes = Math.floor(((maxtime-days*3600*24)-hours*3600)/60);
seconds = Math.floor(maxtime%60);
msg = "倒计时:"+days+"天"+hours+"时"+minutes+"分"+seconds+"秒";//动态显示剩余时间。
document.all["timer"].innerHTML=msg;
maxtime=maxtime-1;
}
else{
clearInterval(timer);
document.all["timer"].innerHTML='不好意思,已经过期了,下次早来吧';
}
}
timer = setInterval("CountDown()",1000);
改了你看看效果。