1
音頻設置爲在特定時間播放,就像內置於我主頁背景中的鬧鐘一樣。它在正確的時間播放。但是,由於某種原因,它也在加載網頁上播放。如果任何人都能弄明白,那將會非常感激,因爲我很無能。音頻聲音播放onload應該是一個定時事件
var date = new Date(),
year = date.getFullYear(),
month = date.getMonth(),
weekday = date.getDay(),
day = date.getDate(),
time = date.getTime(),
timeout1 = new Date(year, month, day, 12, 15, 0, 0).getTime() - time,
timeout2 = new Date(year, month, day, 14, 30, 0, 0).getTime() - time,
timeout3 = new Date(year, month, day, 17, 0, 0, 0).getTime() - time,
timeout4 = new Date(year, month, day, 19, 0, 0, 0).getTime() - time,
timeout5 = new Date(year, month, day, 23, 45, 0, 0).getTime() - time,
mp3 = new Audio("audio/alarm.mp3"),
ogg = new Audio("audio/alarm.ogg"),
audio;
if (typeof mp3.canPlayType === "function" && mp3.canPlayType("audio/mpeg") !== "")
audio = mp3;
else if (typeof ogg.canPlayType === "function" && ogg.canPlayType("audio/ogg") !== "")
audio = ogg;
setTimeout(function(){
if (weekday > 0 && weekday < 6) {
audio.play();
}
}, timeout1);
setTimeout(function(){
if (weekday > 0 && weekday < 6) {
audio.play();
}
}, timeout2);
setTimeout(function(){
if (weekday > 0 && weekday < 6) {
audio.play();
}
}, timeout3);
setTimeout(function(){
if (weekday > 0 && weekday < 6) {
audio.play();
}
}, timeout4);
setTimeout(function(){
if (weekday > 0 && weekday < 6) {
audio.play();
}
}, timeout5);
添加一個'的console.log()'在每個超時的,看看哪一個是打 – Ibu 2013-05-09 17:29:11
絕對是第一個這樣jasonmmiraglia是正確的,到目前爲止,只是搞清楚如何使它正時間 – stesab92 2013-05-09 17:34:39