音樂鬧鐘
有時間顯示,可設定鬧鐘時間,還可播放音樂,範例裡的音樂是"卡農",也可以自己更改連結喜歡的音樂唷!
將下列的程式碼複製起來後貼在 <HEAD>與</HEAD>的中間即可
<script language="javascript">
//Enter path to mid file to play
var musicsrc="http://midi.club.st/midis/crys/crystal9/cry9_25.mid"
function sivamtime() {
now=new Date();
hour=now.getHours();
min=now.getMinutes();
sec=now.getSeconds();
if (min<=9) {
min="0"+min;
}
if (sec<=9) {
sec="0"+sec;
}
if (hour>12) {
hour=hour-12;
add="pm";
}
else {
hour=hour;
add="am";
}
if (hour==12) {
add="pm";
}
if (hour==00) {
hour="12";
}
document.hours.clock.value = (hour<=9) ? "0"+hour : hour;
document.minutes.clock.value = min;
document.seconds.clock.value = sec;
document.ampm.clock.value= add;
setTimeout("sivamtime()", 1000);
}
playit=false
function playmusic(){
musicwin=window.open("","","width=100,height=100")
if (navigator.appName=="Microsoft Internet Explorer")
musicwin.document.write('<bgsound src='+'"'+musicsrc+'"'+' loop="infinite">')
else
musicwin.document.write('<embed src=\"'+musicsrc+'\" hidden="true" border="0" width="20" height="20" autostart="true" loop="true">')
musicwin.document.close()
}
function soundcheck(cbox){
playit=cbox.checked
}
function alarm() {
note = document.arlm.message.value;
if (note == '') {note = 'ALARM!!';}
hrs = document.arlm.hr.value;
min = document.arlm.mts.value;
apm = document.arlm.am_pm.value;
if ((document.hours.clock.value == hrs) &&
(document.minutes.clock.value == min) &&
(document.ampm.clock.value == apm)) {
if (playit)
playmusic()
else
alert(note);
return false}
if (hrs == '') {alert('The Hour field is empty'); return false}
if (min == '') {alert('The Minute field is empty'); return false}
if (apm == '') {alert('The am/pm field is empty'); return false}
if (hrs.length == 1) {document.arlm.hr.value = '0' + hrs}
if (min.length == 1) {document.arlm.mts.value = '0' + min}
if (hrs.length > 2) {alert('The Hour is wrongly typed.'); return false}
if (min.length > 2) {alert('The Minute is wrongly typed.'); return false}
if (apm != 'am' && apm != 'pm' ) {alert('The am/pm is wrongly typed.'); return false}
setTimeout("alarm()", 1000);}
</script>
將下列的程式碼複製起來後貼在 <BODY> 裡面
onLoad="sivamtime()"
將下列的程式碼複製起來後貼在 <BODY> 與 </BODY> 的中間即可
<table border="1" bordercolor=CEE8FF align="center" bgcolor="#F0F8FF" cellspacing="0" cellpadding="2" width="136">
<tr>
<td colspan="4">
<font size="2">
現在時間是:
</font>
</td>
</tr>
<tr>
<td>
<form name="hours">
<p><input type="text" size="2" name="clock"></p>
</form>
</td>
<td>
<form name="minutes">
<p><input type="text" size="2" name="clock" /></p>
</form>
</td>
<td>
<form name="seconds">
<p><input type="text" size="2" name="clock" /></p>
</form>
</td>
<td>
<form name="ampm">
<p><input type="text" size="2" name="clock" /></p>
</form>
</td>
</tr>
</table>
<table border="1" align="center" bordercolor=CEE8FF bgcolor="#F0F8FF" cellspacing="0" cellpadding="2" width="136">
<tr>
<td colspan="3">
<form name="arlm">
<font size="2">
鬧鐘:
</font>
</td>
</tr>
<tr align="center">
<td>
<font size="1" face="verdana, arial, helvetica, ms sans serif">
Hour
</font>
</td>
<td>
<font size="1" face="verdana, arial, helvetica, ms sans serif">
Minute
</font>
</td>
<td>
<font size="1" face="verdana, arial, helvetica, ms sans serif">
am/pm
</font>
</td>
</tr>
<tr align="center">
<td>
<input type="text" size="2" name="hr" onFocus="select()" />
</td>
<td>
<input type="text" size="2" name="mts" onFocus="select()" />
</td>
<td>
<input type="text" size="2" value="am" name="am_pm" onFocus="select()" />
</td>
</tr>
<tr align="left">
<td colspan="3">
<font size="1" face="verdana, arial, helvetica, ms sans serif">
Message
</font>
</td>
</tr>
<tr align="left">
<td colspan="3">
<input type="text" size="15" value="起床啦!!!懶豬" name="message" /><br>
<input type="checkbox" name="C1" value="ON" onClick="soundcheck(this)"> <font size="1" face="verdana, arial, helvetica, ms sans serif">Play music?</font>
</td>
</tr>
<tr>
<td align="center" colspan="3">
<input type="button" size="2" value="OK" onClick="alarm()" />
<input type="button" size="2" value="Reset" onClick="reset()" />
</td>
</tr>
</table>
</form>
出處:摩尼BBS