如标题所述,我希望显示自计数开始计算以来的日期。 这是我从互联网上下载的代码:
<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代码旨在显示我公司最后一次工伤事故的信息 计数工作正常,我希望在&#34; document.write&#34;之后显示。是&#34; countup&#34;中设置的日期。在这个例子2016/05/04中,无论如何要做到这一点,还是我必须手动插入XX写下来的日期?
答案 0 :(得分: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);
&#13;
<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()">
&#13;