fmpq.com
源代码:
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Fmpq教程(fmpq.com)</title> </head> <body> <p>点击按钮创建 AUDIO 元素,并设置 controls 和 src 属性,使用的格式为 .mp3 或 .ogg (依赖浏览器的选择)。</p> <button onclick="myFunction()">点我</button> <script> function myFunction() { var x = document.createElement("AUDIO"); if (x.canPlayType("audio/mpeg")) { x.setAttribute("src","horse.mp3"); } else { x.setAttribute("src","horse.ogg"); } x.setAttribute("controls", "controls"); document.body.appendChild(x); } </script> </body> </html
运行结果