gpt4 book ai didi

javascript - 单击按钮将代码添加到JS

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

因此,我有这些按钮,这些按钮在被按下时会播放声音,并且我想制作一个按钮,使其在按下时可以使这些声音循环播放。我不知道如何正确地解释这一点,所以请只显示代码

function aud1play() {
aud1.src = "aud1.mp3";
aud1.play();
}
document.getElementById('aud1button').addEventListener('click', aud1play);

function aud2play() {
aud2.src = "aud2.mp3";
aud2.play();
}
document.getElementById('aud2button').addEventListener('click', aud2play);

function aud3play() {
aud3.src = "aud3.mp3";
aud3.play();
}
document.getElementById('aud3button').addEventListener('click', aud3play);

有没有办法采用名称(aud1,aud2,aud3)并放入(name).loop;在每个功能下都按下按钮,而无需实际编写(name).loop;给大家?

最佳答案

试试这个

JS:

function play(){
var audio = document.getElementById("audio");
audio.play();
}

HTML5:
<audio controls loop id="audio">
<source src="horse.mp3" type="audio/mpeg">
</audio>

关于javascript - 单击按钮将代码添加到JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44933290/

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