Javascript教程_解决JS 如何判断本机时间 调取图片源码教程
我们一天一共有1440分钟,假设我们有1440个图片,如何才能让 js 读取到本机的时间,然后在相应的时间调取相应的图片出来
比如:
18:00 调取1800.jpg
18:01 调取1801.jpg
以此类推
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>code.js.cn</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body{font-size:12px;background:#eee;}
img{border:1px solid #999;background:#fff;padding:5px;}
#times{color:#FF8000;font: 48px/1.5 bold sans-serif;}
.sh{
zoom:1;background:#eee;/* IE need this set */
filter:progid:DXImageTransform.Microsoft.dropShadow(color='#22000000', OffX=5,OffY=5);
-webkit-box-shadow:4px 4px 4px #999;
-moz-box-shadow:4px 4px 4px #999;
}
</style>
</head>
<body>
<img src="http://www.red86.com/img/upload/beauty/2326.jpg" id="ooxx" alt="" class="sh" />
<p><strong id="times">0</strong> 秒后 <div id="">就能看到下一张</div></p>
</body>
<script type="text/javascript">
ldh={
get:function(x){return typeof x == 'string' ? document.getElementById(x):x},
base:'http://www.red86.com/img/upload/beauty/',
ext:'.jpg',
begin:function (){
var $=this;
this.timer=setInterval(function (){
var x=new Date,m=x.getMinutes();
$.s=x.getSeconds();
if(m==$.now)return $.onMinutes();
$.now=m;
$.file=('0'+x.getHours()).slice(-2)+('0'+m).slice('-2')+$.ext;
$.onNextMinutes()
},1000);
},
onMinutes:function (){
this.get('times').innerHTML=60-this.s
},
onNextMinutes:function (){
this.get('ooxx').src=this.base+this.file
}
};
ldh.begin();
</script>
</html>