当前时间等于特定时间时如何播放声音 [英] How to play sound when the current time equals to specific time
本文介绍了当前时间等于特定时间时如何播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的网页中,我想在当前时间等于例如5:00 pm时播放声音.
In my web page, I would like to play sound when the current time equals to , for example, 5:00 pm.
我所做的是:
<script type='text/css'>
var d = new Date();
var m = d.getMinutes();
var h = d.getHours();
if (h == 17 && m == 00){
document.write = "<embed src =\'notify.mp3\' hidden=\'true\' autostart=\'true\' loop=\'true\'></embed>";
}
</script>
我寻找了一种播放声音的特定功能,但发现document.write
无效且没有意义.
I looked for a specific function that plays the sound and I found document.write
which doesn't work and doesn't make sense.
任何建议我应该做什么
推荐答案
在JS中尝试:
<script>
var d = new Date();
var m = d.getMinutes();
var h = d.getHours();
if (h == 17 && m == 00){
var sound = document.getElementById(sound1);
sound.Play();
}
</script>
不要忘记将其添加为HTML
Dont forget to add this in HTML
<embed src="notify.mp3" autostart="false" width="0" height="0" id="sound1"
enablejavascript="true">
这篇关于当前时间等于特定时间时如何播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文