gpt4 book ai didi

javascript - 每次单击按钮时播放声音

转载 作者:行者123 更新时间:2023-12-03 12:21:15 25 4
gpt4 key购买 nike

我花了一些时间寻找一种在单击链接时播放声音的工作方式,最后想出了以下方法:

<audio id="sound0" src="/sounds/foo">

<a href="javascript:play('sound0');">Click here</a>

<script>function play(sound_id) {
document.getElementById(sound_id).play();
}</script>

现在,这可以正常工作,但仅限于第一次单击链接时;之后,再次点击没有任何效果。

我该如何解决这个问题?

最佳答案

认为您只需要倒带声音。尝试...

 document.getElementById(sound_id).currentTime=0; 
document.getElementById(sound_id).play();

关于javascript - 每次单击按钮时播放声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24440750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com