0

私は髪を引っ張っています: Javascript の時計が機能していません。Firebug を使用してエラーを探していますが、出力が得られません。

The image files are in subfolders Dual_Months and Dual_Numbers. I have added document.write(); in my functions to see if they are firing but I am not getting any response. If anyone sees any obvious errors I would appreciate your help.

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]+'" />'

この行にaがありません+

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 に答える