欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript實現(xiàn)動態(tài)網(wǎng)頁時鐘

 更新時間:2022年06月21日 12:19:03   作者:Cairo960918  
這篇文章主要介紹了JavaScript實現(xiàn)動態(tài)網(wǎng)頁時鐘,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了JavaScript實現(xiàn)動態(tài)網(wǎng)頁時鐘的具體代碼,供大家參考,具體內容如下

設計思路:

1先建立一個數(shù)組保存帶有0?9數(shù)字的10張圖片;

2.通過GETDATE()獲得本地時間保存在變量數(shù)值指明MyTime中;

3. getHours()返回的是24進制即0~23的整數(shù),getMinutes()方法返回一個處于0到59之間的整數(shù),getSeconds()方法返回一個處于0到59之間的整數(shù);

4.通過的setTimeout()每隔1秒調用一次顯示()函數(shù)改變圖像對象的SRC屬性。

串對象的的charAt(ID)方法:返回指定位置處的字符,標識為要尋找的字符的位置的索引整數(shù),0對應左邊第1個字符,1對應左邊第2個字符,如喂的的charAt(1 )則是è;

代碼如下: 

<html>
<head>
<title>時鐘</title>
<meta charset="utf-8">
<style>
*{
?? ?padding:0;
?? ?margin:0;
?? ?}
</style>
<script>
function show(){
?? ?var images=new Array("./images/s0.png","./images/s1.png","./images/s2.png","./images/s3.png","./images/s4.png","./images/s5.png","./images/s6.png","./images/s7.png","./images/s8.png","./images/s9.png");
?? ?var myTime=new Date();
?? ?var hours=myTime.getHours();
?? ?var minutes=myTime.getMinutes();
?? ?var seconds=myTime.getSeconds();
?? ?if(hours<=9){hours="0"+hours;}//補足兩位
?? ?if(minutes<=9){minutes="0"+minutes;}
?? ?if(seconds<=9){seconds="0"+seconds}
?? ?var theString=""+hours+minutes+seconds;//轉換為字符串
?? ?document.getElementById("img0").src=images[theString.charAt(0)];
?? ?document.getElementById("img1").src=images[theString.charAt(1)];
?? ?document.getElementById("img2").src=images[theString.charAt(2)];
?? ?document.getElementById("img3").src=images[theString.charAt(3)];
?? ?document.getElementById("img4").src=images[theString.charAt(4)];
?? ?document.getElementById("img5").src=images[theString.charAt(5)];
?? ?setTimeout("show()",1000);
?? ?}
</script>
</head>
<body onLoad="show()">
<img id="img0" /><img id="img1" />時<img id="img2" /><img id="img3" />分<img id="img4" /><img id="img5" />
</body>
</html>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論