HTML 参考手册
HTML 音频/视频 DOM src 属性
改变视频的来源
源代码:
点击运行 »
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <button onclick="changeSource()" type="button">改变视频的来源</button> <br> <video id="video1" controls="controls" autoplay="autoplay"> <source id="mp4_src" src="/examples/mov_bbb.mp4" type="video/mp4"> <source id="ogg_src" src="/examples/mov_bbb.ogg" type="video/ogg"> 您的浏览器不支持 HTML5 video 标签。 </video> <script> myVid = document.getElementById("video1"); function changeSource() { isSupp = myVid.canPlayType("video/mp4"); if (isSupp == "") { myVid.src = "/examples/movie.ogg"; } else { myVid.src = "/examples/movie.mp4"; } myVid.load(); } </script> <p>Video courtesy of <a href="http://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p> </body> </html>
运行结果:
点击运行 »