日期:2014-05-16  浏览次数:20349 次

改成一个十天的倒计时
求JS大牛把下面的改成一个十天的倒计时,十天之后,这个DIV就消失



<!DOCTYPE HTML>
<html>
 <head>
  <title> New Document </title>
  <meta charset="gb2312">
  <style>
#xs{margin:20px 0 0 0;color:#000;width:400px;margin:0 auto;font-weight:bolder;letter-spacing:5px}
#xs b{color:red;}
  </style>
 </head>
 <body onload="nowTime()">
  <script>
  function nowTime(){
  var td=new Date()
  var h=23-td.getHours()
  if (h<10)h="0"+h;
  var m=59-td.getMinutes()
  if (m<10)m="0"+m;
  var s=60-td.getSeconds()
  if (s<10)
  {s="0"+s
  }else if (s==60)
  {
s="00"
  }
  document.getElementById('xs').innerHTML="<b>距明天还有:</b>"+h+"<b>小时</b>"+m+"<b>分</b>"+s+"<b>秒</b>"
  t=setTimeout('nowTime()',50)
  }
  </script>
  <div id='xs' >
  </div>
 </body>
</html>


------解决方案--------------------
用下面这个试试
设置定时var target = new Date(2012, 06, 9, 00, 00, 00).getTime();06表示7月 
<html> 
<head> 
<title>Javascript写的倒计时效果代码</title> 
</head> 
<body> 
<script language="javascript" type="text/javascript"> 
var target = new Date(2012, 06, 9, 00, 00, 00).getTime(); 
function show_date_time(){ 
setTimeout("show_date_time()", 1000); 
today=new Date();
timeold = target - today.getTime(); 
sectimeold=timeold/1000; 
secondsold=Math.floor(sectimeold); 
msPerDay=24*60*60*1000; 
e_daysold=timeold/msPerDay; 
daysold=Math.floor(e_daysold); 
e_hrsold=(e_daysold-daysold)*24; 
hrsold=Math.floor(e_hrsold); 
e_minsold=(e_hrsold-hrsold)*60; 
minsold=Math.floor((e_hrsold-hrsold)*60); 
seconds=Math.floor((e_minsold-minsold)*60);
if (daysold < 0) {
document.body.removeChild(document.getElementById("TimeCounter_0"));
return null;
}
else { 
if (daysold<10) {daysold="0"+daysold} 
if (hrsold<10) {hrsold="0"+hrsold} 
if (minsold<10) {minsold="0"+minsold} 
if (seconds<10) {seconds="0"+seconds} 
if (daysold<3) {
document.getElementById("TimeCounter_0").innerHTML = "<font color=red>" + daysold + "天" + hrsold + "小时" + minsold + "分" + seconds + "秒</font>"; 
}
else {
document.getElementById("TimeCounter_0").innerHTML = daysold + "天" + hrsold + "小时" + minsold + "分" + seconds + "秒"; 



window.onload=show_date_time;
</script> 
距10天后还有: 
<div id="TimeCounter_0" style="border:1px solid black;margin:5px;padding:2px;width:140px"></div> 
</body> 
</html>
------解决方案--------------------
倒计时总是需要一个参考时间的,要么是开始时间、要么是结束时间。
HTML code
<!DOCTYPE HTML>
<html>
<head>
<title>New Document</title>
<meta charset="utf-8">