首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

【javascript】倒计时有关问题 【火狐浏览器】没有支持【如何修改】

2012-11-17 
【javascript】倒计时问题 【火狐浏览器】没有支持【怎么修改】由于本人JS不好。所以JS写得笨了些。希望高手指教JS

【javascript】倒计时问题 【火狐浏览器】没有支持【怎么修改】
由于本人JS不好。所以JS写得笨了些。希望高手指教

JScript code
 <script language="JavaScript"> function ShowTimes(){ var AfterTime= new Date("12-11-2012 14:00:00"); //这里是北京上市会时间LeaveTime = AfterTime - new Date(); var ne = document.getElementById("dh"); if(0 >= LeaveTime){    clearInterval(id);    ne.innerHTML="已开始";    return false;}LeaveDays=Math.floor(LeaveTime/(1000*60*60*24)); LeaveHours=Math.floor(LeaveTime/(1000*60*60)%24); LeaveMinutes=Math.floor(LeaveTime/(1000*60)%60); LeaveSeconds=Math.floor(LeaveTime/1000%60); var c=new Date(); var q=c.getMilliseconds(); ne.innerHTML="距<font color=red>北京上市会</font>还有<font color=red>"+LeaveDays+"</font>天 <font color=red>"+LeaveHours+"</font>时 <font color=red>"+LeaveMinutes+"</font>分 <font color=red>"+LeaveSeconds+"</font>秒 <font color=red>"+q+"</font>";}var id = setInterval(ShowTimes,10); </script> <script language="JavaScript"> function ShowTimesh(){ var AfterTimes= new Date("12-12-2012 14:00:00"); //这里是上海上市会时间LeaveTimes = AfterTimes - new Date(); var ne = document.getElementById("sh"); if(0 >= LeaveTimes){    clearInterval(id);    ne.innerHTML="已开始";    return false;}LeaveDays=Math.floor(LeaveTimes/(1000*60*60*24)); LeaveHours=Math.floor(LeaveTimes/(1000*60*60)%24); LeaveMinutes=Math.floor(LeaveTimes/(1000*60)%60); LeaveSeconds=Math.floor(LeaveTimes/1000%60); var c=new Date(); var q=c.getMilliseconds(); ne.innerHTML="距<font color=red>上海上市会</font>还有<font color=red>"+LeaveDays+"</font>天 <font color=red>"+LeaveHours+"</font>时 <font color=red>"+LeaveMinutes+"</font>分 <font color=red>"+LeaveSeconds+"</font>秒 <font color=red>"+q+"</font>";}var id = setInterval(ShowTimesh,10); </script> <script language="JavaScript"> function ShowTimesh(){ var AfterTimes= new Date("12-13-2012 14:00:00"); //这里是广州上市会时间LeaveTimes = AfterTimes - new Date(); var ne = document.getElementById("gz"); if(0 >= LeaveTimes){    clearInterval(id);    ne.innerHTML="已开始";    return false;}LeaveDays=Math.floor(LeaveTimes/(1000*60*60*24)); LeaveHours=Math.floor(LeaveTimes/(1000*60*60)%24); LeaveMinutes=Math.floor(LeaveTimes/(1000*60)%60); LeaveSeconds=Math.floor(LeaveTimes/1000%60); var c=new Date(); var q=c.getMilliseconds(); ne.innerHTML="距<font color=red>广州上市会</font>还有<font color=red>"+LeaveDays+"</font>天 <font color=red>"+LeaveHours+"</font>时 <font color=red>"+LeaveMinutes+"</font>分 <font color=red>"+LeaveSeconds+"</font>秒 <font color=red>"+q+"</font>";}var id = setInterval(ShowTimesh,10); </script><span id="dh" style="padding-left:220px;margin:5px;color:#000000; font-size:18px;" ></span><br/><span id="sh" style="padding-left:220px;margin:5px;color:#000000; font-size:18px;" ></span><br/><span id="gz" style="padding-left:220px;margin:5px;color:#000000; font-size:18px;" ></span>


[解决办法]
HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>azhong.com </title><meta name="generator" content="editplus" /><meta name="author" content="" /><meta name="keywords" content="" /><meta name="description" content="" /><style type="text/css">   #liTimeLimit   {       font: 16px Arial, Helvetica, sans-serif;font-weight: bold;color: #00ff06;background-color: #000;height:20px;line-height:20px;width: 150px;text-align: center; margin-top:8px;   }</style></head><body>离15:02 3/27/2013<span id="liTimeLimit">2<span class="witha">天</span> 07:35:50</span><script language="JavaScript" type="text/JavaScript" content="1">      var dDateHead = new Date("15:02 3/27/2013");   function showTimeLimit()   {       setTimeout("showTimeLimit()",1000);       var dNowDay = new Date();       iTimeLimit = dDateHead.getTime()-dNowDay.getTime();       if(iTimeLimit>0){               msSec = 1000;//一秒毫秒数             msMin = 60*msSec;//一分钟毫秒数           msHour = 60*msMin;//一小时毫秒数           msDay = 24*msHour;//一天的毫秒数           iDay=Math.floor(iTimeLimit/msDay);           iHour=Math.floor(iTimeLimit/msHour);           iMin=Math.floor((iTimeLimit-iHour*msHour)/msMin);           iSec=Math.floor((iTimeLimit-iHour*msHour-iMin*msMin)/msSec);           iHour = iHour>=24?Math.floor(iHour%24):iHour;           iHour = iHour<10&&iHour>0?"0"+iHour:iHour;           iMin = iMin<10?"0"+iMin:iMin;           iSec = iSec<10?"0"+iSec:iSec;           document.getElementById("liTimeLimit").innerHTML=iDay+"<span class=\"witha\">天</span>"+iHour+":"+iMin+":"+iSec;       }          }showTimeLimit();</script></body></html> 


[解决办法]
同意楼上的,日期字符串格式问题,把-换成/就行了,用replace函数

热点排行