运行 ❯
获取您
的
网站
×
更改方向
保存代码
更改主题,暗/亮
前往 Spaces
<!DOCTYPE html> <html> <body> <p>Click the button to create two SOURCE elements, and append them to the AUDIO element.</p> <audio controls id="myAudio" autoplay> Your browser does not support the audio tag. </audio><br> <p id="demo"></p> <button onclick="myFunction()">Try it</button> <script> function myFunction() { var x = document.createElement("SOURCE"); x.setAttribute("src", "horse.mp3"); x.setAttribute("type", "audio/mpeg"); document.getElementById("myAudio").appendChild(x); var y = document.createElement("SOURCE"); y.setAttribute("src", "horse.ogg"); y.setAttribute("type", "audio/ogg"); document.getElementById("myAudio").appendChild(y); document.getElementById("demo").innerHTML = "The audio player now works as it should. Press play to listen to the sound of a horse."; } </script> </body> </html>