给小孩子做网站,爱凡客,爱站网源码,桂林漓江旅游功能#xff1a;用切换图片0-9效果显示当前系统时间
属性#xff1a;img的src
1.用到
new Date()
getHours(),getMinutes(),getSeconds()
getFullyear(),getMouth() 1月数需要加1,getDay()星期为0#xff0c;1#xff0c;2#xff0c;3#xff0c;4#xff0c;5用切换图片0-9效果显示当前系统时间
属性img的src
1.用到
new Date()
getHours(),getMinutes(),getSeconds()
getFullyear(),getMouth() 1月数需要加1,getDay()星期为0123456 2.单位数转换成双位字符串的函数
function toDou(n){
if(n10){
return 0 n;//任意数加字符串结果为字符串的拼接
}
else{
return n;//任意数加空字符串结果为字符串
}
} 3.获取字符串用str.charAt(i)否则不兼容 4.计时器
开启setInterval(fn,时间无限循环setTimeout(fn,时间)只执行一次
关闭clearInterval,clearTimeout
关闭方式
var timernull;
timersetInterval(fn,时间;
clearInterval(timer); 5.获取系统时间转化成6位字符串
var strtoDou(oDate.getHours()) toDou(oDate.getMinutes()) toDou(oDate.getSeconds) 6.改变图片路径
aImag[i].srcimg/ str.charAt(i) .png 7.setInterval(fn,时间是时间后执行fn,显示会有些问题为了一开始就执行fn,
代码顺序
fn(...);
setInterval(fn,时间;
fn(); ///
!DOCTYPE htmlhtmlheadmeta charsetutf-8meta http-equivX-UA-Compatible contentIEedge,chrome1titleExamples/titlemeta namedescription contentmeta namekeywords content
link hrefcss1.css relstylesheet typetext/csscharsetUTF-8/headbodydiv iddiv1 img srcimg/0.png/img srcimg/0.png/:img srcimg/0.png/img srcimg/0.png/:img srcimg/0.png/img srcimg/0.png//divscript srcjs1.js /script /body/html
css
body{ background :#000; font-size: 50px;}#div1{ background:#fff; width:680px; height:110px; padding:0; margin-top:50px; margin-left:20%; text-align: center;}img{ width:72px; height:85px; margin-top:10px; }
/js
window.οnlοadfunction(){ function gogo(){var oDatenew Date();var aImgdocument.getElementsByTagName(img);function toDou(n){ if(n10){ return 0 n; } else{ return n; }};var strtoDou(oDate.getHours()) toDou(oDate.getMinutes()) toDou(oDate.getSeconds());for(var i0;iaImg.length;i ){ aImg[i].srcimg/ str.charAt(i) .png;}};setInterval(gogo,1000);gogo();};
更多专业前端知识请上
【猿2048】www.mk2048.com