W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h3>演示如何访问 AUDIO 元素</h3> <audio id="myAudio" controls> <source src="/i/horse.ogg" type="audio/ogg"> <source src="/i/horse.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audio> <p>请点击按钮来获得以秒计的音频时长。</p> <p id="demo"></p> <button onclick="myFunction()">试一下</button> <script> function myFunction() { var x = document.getElementById("myAudio").duration; document.getElementById("demo").innerHTML = x; } </script> </body> </html>