HTML Audio/Video DOM currentSrc 属性 详解
HTML基础 2022-06-02 15:33:0312小码哥的IT人生shichen
HTML Audio/Video DOM currentSrc 属性
实例
获得当前视频的 URL:
myVid=document.getElementById("video1"); alert(myVid.currentSrc);
完整实例【亲自试一试】:
<!DOCTYPE html> <html> <body> <button onclick="getVid()" type="button">获得当前视频的 URL</button> <br /> <br /> <video id="video1" controls="controls"> <source src="/demo/example/html5/mov_bbb.mp4" type="video/mp4"> <source src="/demo/example/html5/mov_bbb.ogg" type="video/ogg"> Your browser does not support HTML5 video. </video> <script> myVid=document.getElementById("video1"); function getVid() { alert(myVid.currentSrc); } </script> </body> </html>
可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html
定义和用法
currentSrc 熟悉返回当前音频/视频的 URL。
如果未设置音频/视频,则返回空字符串。
浏览器支持
所有主流浏览器都支持 currentSrc 属性。
注释:Internet Explorer 8 或更早的浏览器不支持该属性。
语法
audio|video.currentSrc
技术细节
返回值 | 字符串,表示音频/视频的当前 URL |
---|