简单教程
提交运行
代码编辑器:
<audio id="myAudio" controls> <source src="/static/i/html/horse.ogg" type="audio/ogg"> <source src="/static/i/html/horse.mp3" type="audio/mpeg"> 你的浏览器不支持audio元素。 </audio><br> <button onclick="enableAutoplay()" type="button">启用 autoplay</button> <button onclick="disableAutoplay()" type="button">禁用 autoplay</button> <button onclick="checkAutoplay()" type="button">检查 autoplay 状态</button> <script> var x = document.getElementById("myAudio"); function enableAutoplay(){ x.autoplay = true; x.load(); } function disableAutoplay(){ x.autoplay = false; x.load(); } function checkAutoplay(){ alert(x.autoplay); } </script>
运行结果: