Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在不同的单元格中使用相同的Javascript计算通过的天数_Javascript_Html_Counter - Fatal编程技术网

在不同的单元格中使用相同的Javascript计算通过的天数

在不同的单元格中使用相同的Javascript计算通过的天数,javascript,html,counter,Javascript,Html,Counter,我目前正在尝试用几个计数器填充一个html表,一个在另一个下面,以显示事件发生后的几天。 多亏了互联网,我最终得到了以下脚本: <script language="JavaScript1.2" type="text/javascript">function setcountup(theyear,themonth,theday){ yr=theyear;mo=themonth;da=theday } //////////CONFIGURE

我目前正在尝试用几个计数器填充一个html表,一个在另一个下面,以显示事件发生后的几天。 多亏了互联网,我最终得到了以下脚本:

    <script language="JavaScript1.2" type="text/javascript">function
     setcountup(theyear,themonth,theday){
     yr=theyear;mo=themonth;da=theday
     }

   //////////CONFIGURE THE countup SCRIPT HERE//////////////////

   //STEP 1: Configure the date to count up from, in the format year, month, day:
   //This date should be less than today
   setcountup(2012,9,19)

   //STEP 2: Configure text to be attached to count up
   var displaymessage=""


   //STEP 3: Configure the below 5 variables to set the width, height, background color,       
   and text style of the countup area
   var countupwidth='90%'
   var countupheight='40px' //applicable only in NS4
   var countupbgcolor=''
   var opentags='<font face="Verdana"><large>'
   var closetags='</large></font>'

   //////////DO NOT EDIT PASS THIS LINE//////////////////

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

   function start_countup(){
   if (document.layers)
   document.countupnsmain.visibility="show"
   else if (document.all||document.getElementById)
   crosscount=document.getElementById&&!document.all?   
   document.getElementById("countupie") : countupie
   countup()
   }

   if (document.all||document.getElementById)
   document.write('<span id="countupie" style="width:'+countupwidth+'; background-    
   color:'+countupbgcolor+'"></span>')

   window.onload=start_countup


   function countup(){
   var today=new Date()
   var todayy=today.getYear()
   if (todayy < 1000)
   todayy+=1900
   var todaym=today.getMonth()
   var todayd=today.getDate()
   var todayh=today.getHours()
   var todaymin=today.getMinutes()
   var todaysec=today.getSeconds()
   var todaystring=montharray[todaym]+" "+todayd+", "+todayy+"     
   "+todayh+":"+todaymin+":"+todaysec
   paststring=montharray[mo-1]+" "+da+", "+yr
   paststring="10:00"+montharray[mo-1]+" "+da+", "+yr
   dd=Date.parse(todaystring)-Date.parse(paststring)
   dday=Math.floor(dd/(60*60*1000*24)*1)
   dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
   dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
   dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)

   if (document.layers){
   document.countupnsmain.document.countupnssub.document.write(opentags+dday+ " days    
   "+displaymessage+closetags)//to get more detail, enter one of the following in  the   
   write line(also in the else): +dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds    
   "
   document.countupnsmain.document.countupnssub.document.close()
   }
   else if (document.all||document.getElementById)
   crosscount.innerHTML=opentags+dday+ " days "+displaymessage+closetags//+dhour+"  
   hours, "+dmin+" minutes, and "+dsec+" seconds "

   setTimeout("countup()",1000)
   }
   </script>
函数
设置计数(年、月、日){
年=年;月=月;日=日
}
//////////在此配置倒计时脚本//////////////////
//步骤1:以年、月、日的格式配置要从开始计数的日期:
//这个日期应该比今天短
设置计数(2012,9,19)
//步骤2:将要附加的文本配置为向上计数
var displaymessage=“”
//第三步:配置以下5个变量来设置宽度、高度、背景色、,
以及倒计时区域的文本样式
var countupwidth='90%'
var countupsight='40px'//仅适用于NS4
var countupbgcolor=''
var opentags=''
var closetags=''
//////////不要编辑此行//////////////////
var montharray=新
数组(“一月”、“二月”、“三月”、“四月”、“五月”、“六月”、“七月”、“八月”、“九月”、“十月”、“十一月”、“十二月”)
变量交叉计数=“”
函数启动\u计数(){
if(document.layers)
document.countupnsmain.visibility=“show”
else if(document.all | | document.getElementById)
交叉计数=document.getElementById&!document.all?
document.getElementById(“countupie”):countupie
倒计时
}
if(document.all | | document.getElementById)
文件。写入(“”)
window.onload=start\u countup
函数倒计时(){
var today=新日期()
var todayy=today.getYear()
如果(今天<1000)
今天+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+“”+todayd+“,“+todaydy+”
“+todayh+”:“+todaymin+”:“+todaysec
paststring=montharray[mo-1]+“+da+”,“+yr”
paststring=“10:00”+蒙塔雷[mo-1]+“+da+”,“+yr”
dd=Date.parse(todaystring)-Date.parse(paststring)
dday=数学楼层(dd/(60*60*1000*24)*1)
dhour=数学楼层((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=数学楼层((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=数学楼层(((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
if(document.layers){
document.countupnsmain.document.countupnssub.document.write(opentags+dday+“天
“+displaymessage+closetags)//要获取更多详细信息,请在
写行(也在else中):+dhour+“小时”,“+dmin+”分钟和“+dsec+”秒
"
document.countupnsmain.document.countupnssub.document.close()
}
else if(document.all | | document.getElementById)
crosscount.innerHTML=opentags+dday+“days”+displaymessage+closetags//+dhour+”
小时、“+dmin+”分钟和“+dsec+”秒”
设置超时(“countup()”,1000)
}
现在,每个单元格行都有一个用于不同事件的计数器。 我似乎无法将这段代码放在每段代码中,因为它会产生冲突(我认为)

我是个新手,我必须把这件事弄清楚。 谁能帮我一下,或者给我指出正确的方向


提前谢谢你

我花了很多时间试图让你发布的代码生效,我不得不说,这是一些非常糟糕的代码。有很多不需要的代码,如:

paststring=montharray[mo-1]+" "+da+", "+yr
paststring="10:00"+montharray[mo-1]+" "+da+", "+yr
还有很多只是一般格式的疯狂。我相信我已经成功了,而且它比以前更容易阅读。这把小提琴应该有助于你工作


您能给我们提供一些关于什么不起作用的更多信息吗?通常,当你发布关于堆栈溢出的问题时,你应该显示你已经尝试了什么,它当前正在做什么,以及你希望它做什么。好吧,如果我把它放在html的一个单元格中,我会得到一个计数器,显示过去的日子。这样就行了。但是如果我把它粘贴到下一个单元格中,每个单元格都会变成空的。当代码只有一个实例时,代码本身就会工作。但是当我在一个页面上有多个页面时,它就停止工作了。如果我下面的回答对您有所帮助,请务必接受它。谢谢答案很完美,但我不知道如何接受。我想在这里发一封感谢信,但显然这是不允许的。