慕容7034939
2016-12-27 22:41
<DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<title></title>
<script>
function toDou(n)
{
if(n<10)
{return '0'+n;}
else{return ''+n;}
}
window.onload=function ()
{
var aImg=document.getElementsByTagName('img')
function tick()
{
var oDate=new Date()
var str=toDou(oDate.getHours())+toDou(oDate.getMinutes())+toDou(oDate.getSeconds())
for(var i=0;i<aImg.length;i++)
{
aImg.src='images/'+str.charAt(i)+'.png';
}
}
setInterval(tick,1000)
tick();
}
</script>
</head>
<body style="background:black; color:white; font-size:59px;"/>
<img src="images/0.png" />
<img src="images/0.png" />
:
<img src="images/0.png" />
<img src="images/0.png" />
:
<img src="images/0.png" />
<img src="images/0.png" />
</body>
</html>
<script> function toDou(n) { if (n < 10) { return '0' + n; } else { return '' + n; } } window.onload = function() { var aImg = document.getElementsByTagName('img'); function tick() { var oDate = new Date(); var str = toDou(oDate.getHours()) + toDou(oDate.getMinutes()) + toDou(oDate.getSeconds()); for (var i = 0; i < aImg.length; i++) { aImg[i].src = 'images/' + str.charAt(i) + '.png'; } } setInterval(tick, 1000); tick(); } </script>
aImg是个数组,你的 数组赋值 错了应该:aImg[i].src = 'images/' + str.charAt(i) + '.png';
你是不是想做个图片时间,不过我知识还不够,看不懂哪错了
JavaScript入门篇
739817 学习 · 9566 问题
相似问题