1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <script type= "text/javascript" > function itinerary() { today = new Date(); var div = document.getElementById( "div" ); var jsondata = { "weeks" :[ { "week" : "星期日" }, //0 { "week" : "星期一" }, //1 { "week" : "星期二" }, //2 { "week" : "星期三" }, //3 { "week" : "星期四" }, //4 { "week" : "星期五" }, //5 { "week" : "星期六" }, //6 ], "schedule" :[ //{"week":"星期幾", "from":"幾點", "to":"到幾點", "html":"事件內容"}, { "week" : "-1" , "from" : "23" , "to" : "24" , "html" : "每日事件" }, { "week" : "-1" , "from" : "0" , "to" : "1" , "html" : "每日事件" }, { "week" : "0" , "from" : "0" , "to" : "24" , "html" : "星期日事件" }, { "week" : "1" , "from" : "0" , "to" : "24" , "html" : "星期一事件" }, { "week" : "2" , "from" : "0" , "to" : "24" , "html" : "星期二事件" }, { "week" : "3" , "from" : "0" , "to" : "24" , "html" : "星期三事件" }, { "week" : "4" , "from" : "0" , "to" : "24" , "html" : "星期四事件" }, { "week" : "5" , "from" : "9" , "to" : "24" , "html" : "星期五事件" }, { "week" : "6" , "from" : "8" , "to" : "12" , "html" : "星期六事件" }, ] }; for (i=0;i<jsondata.schedule.length;i++) if (today.getDay() == jsondata.schedule[i].week || jsondata.schedule[i].week == -1) if (today.getHours()>=jsondata.schedule[i].from && today.getHours()<jsondata.schedule[i].to) div.innerHTML += jsondata.schedule[i].html + "<br />" ; } window.onload = itinerary; </script> <div id= "div" align= "center" >--- List of itineraries ---<br /></div> |
簡單利用JavsScript讀取JSON格式之星期及行程表內容,
比起採用陣列方式來紀錄更加清楚明瞭,
若搭配Google spreadsheet將更加簡單方便。
沒有留言:
張貼留言