0

我正在拔头发:我的 Javascript 时钟不工作。我正在使用 Firebug 查找错误,但没有得到任何输出。

图像文件位于子文件夹Dual_MonthsDual_Numbers. 我已经添加document.write();了我的函数以查看它们是否正在触发,但我没有得到任何响应。如果有人看到任何明显的错误,我将不胜感激。

var imageclock=new Object()
imageclock.digits=["num_0.png", "num_1.png", "num_2.png", "num_3.png", "num_4.png", "num_5.png", "num_6.png", "num_7.png", "num_8.png", "num_9.png", "am.png", "pm.png", "colon.png"]
imageclock.months=["dual_jan.png", "dual_feb.png", "dual_mar.png", "dual_apr.png", "dual_may.png", "dual_jun.png", "dual_jul.png", "dual_aug.png", "dual_sept.png", "dual_oct.png", "dual_nov.png", "dual_dec.png"]
imageclock.instances=0
var preloadimages=[]
var preloadmonths=[]
for (var i=0; i<imageclock.months.length; i++){ //preload images
  preloadmonths[i]=new Image()
  preloadmonths[i].src="Dual_Months"+imageclock.months[i]
}
for (var i=0; i<imageclock.digits.length; i++){ //preload images
  preloadimages[i]=new Image()
  preloadimages[i].src="Dual_Numbers"+imageclock.digits[i]
}
imageclock.imageHTML=function(timestring){
//return timestring (ie: 1:56:38) into string of images instead
  var sections=timestring.split("/")
  for (var i=0; i<sections.length; i++){
    if (sections[i] == sections[0])
      sections[i]='<img src="Dual_Months/'+imageclock.months[0]+'" />'
    else if(sections[i].length==1 && sections[i] == sections[1])
      sections[i]='<img src="Dual_Numbers/'+imageclock.digits[0]'" />'+'<img src="Dual_Numbers/'+imageclock.digits[parseInt(sections[i])]+'" />'
    else if(sections[i].length!=1 && sections[i] != sections[0])
      sections[i]='<img src="Dual_Numbers/'+imageclock.digits[parseInt(sections[i].charAt(0))]+'" />'+'<img src="Dual_Numbers/'+imageclock.digits[parseInt(sections[i].charAt(1))]+'" />'
  }
  return sections[0]+'<img src="single_nums/'+imageclock.digits[12]+'" />'+sections[1]+'<img src="single_nums/'+imageclock.digits[12]+'" />'+sections[2]
}
imageclock.display=function(){
  var clockinstance=this
  this.spanid="clockspan"+(imageclock.instances++)
  document.write('<span id="'+this.spanid+'"></span>')
  this.update()
  setInterval(function(){clockinstance.update()}, 1000)
}
imageclock.display.prototype.update=function(){
  var dateobj=new Date()
  var currentdate=dateobj.getMonth()+"/"+dateobj.getDay()
  document.write(currentdate)
  var currenttimeHTML=imageclock.imageHTML(currentdate)
  document.getElementById(this.spanid).innerHTML=currenttimeHTML
}
new imageclock.display();
4

2 回答 2

2

您的脚本中有一些语法错误。

'在这一行的末尾缺少 a :

sections[i]='<img src="Dual_Months/'+imageclock.months[0]+'" />

sections[i]='<img src="Dual_Months/'+imageclock.months[0]+'" />'

+在这一行中缺少一个:

sections[i]='<img src="Dual_Numbers/'+imageclock.digits[0]'" />'+'<img src="Dual_Numbers/'+imageclock.digits[parseInt(sections[i])]+'" />'

sections[i]='<img src="Dual_Numbers/'+imageclock.digits[0]+'" />'+'<img src="Dual_Numbers/'+imageclock.digits[parseInt(sections[i])]+'" />'
于 2012-12-03T04:31:11.200 回答
2

你的 javascript 得到了 snytax 错误,首先纠正它

        if (sections[i] == sections[0])

            sections[i]='<img src="Dual_Months/'+imageclock.months[0]+'" />'

        else if(sections[i].length==1 && sections[i] == sections[1])

        sections[i]='<img src="Dual_Numbers/'+imageclock.digits[0]+'" />'+'<img src="Dual_Numbers/'+imageclock.digits[parseInt(sections[i])]+'" />'

        else if(sections[i].length!=1 && sections[i] != sections[0])
于 2012-12-03T04:31:58.520 回答