所用知识点:
- 建立时间对象. var date=new Date();
- 获取小时 var hour=date.getHours();
- 获取分钟 var minu=date.getMinutes();
- 获取秒 var sec=date=getSeconds();
- 设置图片src属性:
实例:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script ytpe='text/javascript'>
function f1(){
var date=new Date();
var hour=date.getHours(); //获取小时
var minu=date.getMinutes();//分钟
hour=hour<10?'0'+hour:hour;
minu=minu<10?'0'+minu:minu;
var addr=hour+'_'+minu;
document.getElementById('img').src='images/'+addr+'.jpg';
}
onload=function(){
f1();
setInterval(f1,1000);
};
</script>
</head>
<body>
<img src='images/00_01.jpg' id='img' />
</body>
</html>