该程序的目的是以数字时钟的形式显示数字数字的图片。我正在尝试检查变量的计数,s
然后使用在 switch 语句中生成的结果元素 ID 来显示正确的图片。但是这段代码似乎不起作用。第一次使用javascript,请温柔。
function startTime(){
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
m=checkTime(m);
s=checkTime(s);
showClockSeconds(s);
t=setTimeout(function(){startTime()},500);
}
function showClockSeconds(s){
var Zero = document.createElement("img");
Zero.setAttribute("src","http://i1363.photobucket.com/albums/r703/franco_fantillo/Zero_zpsd7f11364.jpg");
Zero.setAttribute("alt" ,"No Image");
var One = document.createElement("img");
One.setAttribute("src","http://i1363.photobucket.com/albums/r703/franco_fantillo/Zero_zpsd7f11364.jpg");
One.setAttribute("alt" ,"No Image");
switch(s)
{
case 0:
document.getElementById('Seconds').append Child(Zero);
break;
case 1:
document.getElementById('Seconds').append Child(One);
break;
}
}
function checkTime(i)
{
if (i<10)
{
i="0" + i;
}
return i;
}
</script>
...
<div id="Seconds"></div>