JavaScript 参考手册
Audio loop 属性
将音频设置为循环播放
源代码:
点击运行 »
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>蜜蜂教程(mifengjc.com)</title> </head> <body> <audio id="myAudio" controls> <source src="/examples/horse.ogg" type="audio/ogg"> <source src="/examples/horse.mp3" type="audio/mpeg"> 你的浏览器不支持audio 元素。 </audio><br> <button onclick="enableLoop()" type="button">允许循环播放</button> <button onclick="disableLoop()" type="button">禁止循环播放</button> <button onclick="checkLoop()" type="button">检查循环状态</button> <script> var x = document.getElementById("myAudio"); function enableLoop() { x.loop = true; x.load(); } function disableLoop() { x.loop = false; x.load(); } function checkLoop() { alert(x.loop); } </script> </body> </html>
运行结果:
点击运行 »