2016-05-30 62 views
0

正如標題所述,我期待顯示從countup開始計數以來的日期。 下面是我從網上下了代碼:顯示countup的日期

<html> 
<header> 
    <marquee meta http-equiv="Content-Type" content="text/html;charset=utf8" Class="Scroller" behavior="scroll" direction="left" width="100%" height="50" scrollamount="8" scrolldelay="0" onmouseover="this.stop()" onmouseout="this.start()"> 
    <font size="5" face="Arial, Helvetica, sans-serif"> 
    <strong> 
    <em> 
     <script type="text/javascript"> 
     var montharray = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") 

     function countup (yr, m, d) { 
      var today = new Date() 
      var todayy = today.getYear() 
      if (todayy < 1000) 
       todayy+=1900 
      var todaym = today.getMonth() 
      var todayd = today.getDate() 
      var todaystring = montharray[todaym]+" "+todayd+", "+todayy 
      var paststring = montharray[m-1]+" "+d+", "+yr 
      var difference = (Math.round((Date.parse(todaystring) - Date.parse(paststring))/(24 * 60 * 60 * 1000)) * 1) 
      difference += " jours" 
      document.write("<FONT COLOR='RED'>Nombre de jours sans accident : " + difference + " Dernier Accident le XX Accident sans arrêt. En chargeant son véhicule, la main du technicien a heurté un tuyau en inox, lui occasionant une plaie au doigt </FONT>") 
     } 
     //Entrer la date AAAA/MM/JJ 
     countup(2016, 05, 04) 
     </script> 
    </em> 
</header> 
<body> 
</body> 
</html> 

HTML代碼打算在我公司 的計數進位工作正常顯示上次工作事故的信息,在「文件後,我想什麼顯示。寫「是在這個例子2016/05/04中的」countup「中設置的日期,是否有這樣做,或者我是否必須手動插入XX日期的日期?

+0

有你嘗試添加'文件撰寫(YR + 「/」 + M + 「/」 + d);'第一文件撰寫後? – moped

+0

我可能做錯了 我試過document.write(yr +「/」+ m +「/」+ d)(「 Nombre de jours sans accident .... and whats displayed is只有日期 如果我用(yr +「/」+ m +「/」+ d)替換「XX」;返回值是NaNa – Ajohnson

回答

0

var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); 
 

 
    function countup(yr,m,d){ 
 
     var today = new Date(); 
 
     var todayy = today.getYear(); 
 
     if (todayy < 1000) { 
 
      todayy+=1900; 
 
     } 
 
     var todaym = today.getMonth(); 
 
     var todayd = today.getDate(); 
 

 
     var todaystring = montharray[todaym]+" "+todayd+", "+todayy; 
 
     var paststring = montharray[m-1]+" "+d+", "+yr; 
 
     var difference=(Math.round((Date.parse(todaystring)-Date.parse(paststring))/(24*60*60*1000))*1); 
 
     difference+=" jours"; 
 
     
 
     var date = yr+'/'+m+'/'+d; 
 

 
     document.write("<FONT COLOR='RED'>Nombre de jours sans accident : "+difference+" Dernier Accident le "+date+" Accident sans arrêt</FONT>"); 
 
    } 
 

 
//Entrer la date AAAA/MM/JJ 
 
countup(2016,05,04);
<marquee meta http-equiv="Content-Type" content="text/html;charset=utf8" Class="Scroller" behavior="scroll" direction="left" width="100%" height="50" scrollamount="8" scrolldelay="0" onmouseover="this.stop()" onmouseout="this.start()">

+0

我不得不提高arround以將日期合併到document.write內部,它的工作原理與一個魅力 var date = todayy +'/'+ todaym +'/'+ todayd; document.write(「 Nombre de jours sans accident:」+ difference +「Dernier Accident le」+ date + 「Accident sansarrêt...」); 我想感謝HåkenLid&jserodio解決我的問題 – Ajohnson

+0

我修改了一下我的答案,所以現在日期顯示爲紅色。喲你今天= today.getMonth()'因爲月份從零開始。 –

+0

我現在實際上遇到了問題。 該countup日期是2016/05/04,什麼顯示是2016/05/30 – Ajohnson