打开记事本,把以下代码另存为 闹钟.hta即可使用
------------------------------
<body>
现在时间是: <span id="now_time"></span><br />
闹钤时间<input id='note_time' maxlength=8 style="ime-mode:disabled;"/>HH:MM:SS格式<br />
闹钤音乐<input type=file id='note_music' /> <input type=button οnclick="listen();" value="试听" /><input type=button οnclick="listen(1);" value="停止" /><br />
<input type=button οnclick="set_note()" value="应用设置" />
<span id="setting"></span>
<bgsound id=player style="display:;" AutoStart = "true" src="*.mp3" />
</body>
<script>
function get_obj(id){
return document.getElementById(id);
}
function listen(stop){
if (stop){
return get_obj('player').src = '*.mp3';
}
var music_path = get_obj('note_music').value;
if (!/.+\.mp3$/i.test(music_path)){
return alert('请先选择音乐文件');
}
get_obj('player').src = music_path;
}
function set_note(){
var note_time = get_obj('note_time').value;
var note_music = get_obj('note_music').value;
if (!/^(\d{2})\:(\d{2})\:(\d{2})$/.test(note_time)){
return alert('请按HH:MM:SS格式输入要响铃的时间');
}
var date = new Date();
var note_sec = new Date(date.getFullYear(), date.getMonth(), date.getDate(), RegExp.$1, RegExp.$2, RegExp.$3).getTime() - date.getTime();//化成毫秒
if (!/.+\.mp3$/i.test(note_music)){
return alert('请先选择音乐文件');
}
window.note_path = note_music;
clearTimeout(window.noter);
window.noter = setTimeout(function (){
get_obj('player').src = window.note_path;
get_obj('setting').innerHTML = '闹钤时间到了.';
},note_sec);
get_obj('setting').innerHTML = '闹钤已经设定在:' + note_time;
}
window.onload = function (){
setInterval(function (){
var date = new Date();
var now_txt = date.getHours().toString().replace(/^(\d)$/, '0$1') + ':';
now_txt += date.getMinutes().toString().replace(/^(\d)$/, '0$1') + ':';
now_txt += date.getSeconds().toString().replace(/^(\d)$/, '0$1');
get_obj('now_time').innerHTML = now_txt;
}, 1000);
}
</script>
--------------------------
只能设置一个响铃时间,当时间到了时,自动播放音乐,
误差可能在一秒以下