gpt4 book ai didi

带图像的 Javascript 时钟

转载 作者:行者123 更新时间:2023-11-28 16:09:08 28 4
gpt4 key购买 nike

我正在抓狂:我的 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();

最佳答案

您的 javascript get 语法错误请先纠正

        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])

关于带图像的 Javascript 时钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13677084/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com