Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在我的页面中声明了一个音频文件:
var audio = new Audio('my.mp3');
然后我使用点击事件来播放它:
$(document).click(function () { audio.currentTime = 0; // to make sure it play from the begain audio.play(); })
只能在第一次点击的时候播放,结束后点击文件就不能再播放了,怎么让它再播放呢?
我在 Chrome 中对此进行了测试,但由于 audio.currentTime 语句而发生异常。
这有效(也在 IE9 中):
$(document).click(function () { audio.src = "my.mp3"; audio.play(); })