JavaScript 参考手册
Audio autoplay 属性
启用自动播放,并重新加载视频
源代码:
点击运行 »
<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="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>
运行结果:
点击运行 »