代码呈上
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script type="text/javascript">
var date = new Date();
date.setDate(15); //日设置
date.setMonth(1);
date.setFullYear(2019);
date.setHours(11);
date.setMinutes(11);
date.setSeconds(2);
setInterval(function(){
if((new Date().getTime() - date.getTime() > 0)&&(new Date().getTime() - date.getTime() <30000))
//当到达设定时间 响铃半分钟
{
console.log('lalala');
//动态设置audio结点
var audio = document.createElement("audio");
audio.src = "../../music/坦克大战.mp3";
audio.play();
}
},5000);
</script>
</body>
</html>
运行时可能会有bug,如果是chrome浏览器,可能有这样的报错:
Uncaught(in promise)DOMException:play()
处理方法