這篇文章主要介紹了JavaScript每天定時更換皮膚樣式的方法,涉及javascript針對時間及css樣式的相關操作技巧,需要的朋友可以參考下
本文實例講述了JavaScript每天定時更換皮膚樣式的方法。分享給大家供大家參考。具體分析如下:
這段js代碼通過每天在不同時段自動更換網頁調用的樣式表,實現更換皮膚的功能。
- <script type="text/JavaScript">
- <!--
- function getStylesheet() {
- var currentTime = new Date().getHours();
- if (0 <= currentTime&¤tTime < 5) {
- document.write("<link rel='stylesheet' href='night.css' type='text/css'>");
- }
- if (5 <= currentTime&¤tTime < 11) {
- document.write("<link rel='stylesheet' href='morning.css' type='text/css'>");
- }
- if (11 <= currentTime&¤tTime < 16) {
- document.write("<link rel='stylesheet' href='day.css' type='text/css'>");
- }
- if (16 <= currentTime&¤tTime < 22) {
- document.write("<link rel='stylesheet' href='evening.css' type='text/css'>");
- }
- if (22 <= currentTime&¤tTime <= 24) {
- document.write("<link rel='stylesheet' href='night.css' type='text/css'>");
- }
- }
- getStylesheet();
- -->
- </script>
- <noscript>
- <link href="main.css" rel="stylesheet" type="text/css">
- </noscript>
希望本文所述對大家的javascript程序設計有所幫助。
新聞熱點
疑難解答
圖片精選