使用JS编写控制器上的(闹钟)

//声音时间输出的对象

var this_jfuj='2017-12-30 12:12:50';
//设置时间的文本

function get_Date(){


//创建新的时间文本

var this_jfuj=new Date();

//返回完整的时间
return this_jfuj.getFullYear()+'-'+(this_jfuj.getMonth()+1)+'-'+this_jfuj.getDate()+' '+this_jfuj.getHours()+':'+this_jfuj.getMinutes()+':'+this_jfuj.getSeconds();

}

//设置闹钟

function set_date(){

//获取当前时间

var wz_date    =    get_Date();

 

if(wz_date==this_jfuj){
//打印,已经响了
console.log(wz_date+'—已经响了');    
//播放音乐
document.write('<audio autoplay="autoplay"><source src="后弦 - 下完这场雨.mp3" type="audio/mpeg"></audio>');
return false;
}
//显示响过的

console.log(wz_date+'-此时没有响');

window.setTimeout(function(){
//调用函数
set_date();

},1000);

}
set_date();

 

posted @ 2017-12-30 11:59  世山海  阅读(1059)  评论(0编辑  收藏  举报