English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
src属性反映HTML媒体元素的src 属性的值,该属性指示要在元素中使用的媒体资源的URL。
HTML Audio/Video DOM Reference Manual
改变视频的来源:
!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>HTML 音频/视频 src 属性使用-基础教程(oldtoolbag.com)</title> </head> <body> <button onclick="changeSource()" type="button">改变视频的来源</button> <br> <video id="video1" controls="controls" autoplay="autoplay"> <source id="mp4_src" src="mov_bbb.mp4" type="video/mp4"> <source id="ogg_src" src="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="movie.ogg"; } else { myVid.src="movie.mp4"; } myVid.load(); } </script> </body> </html>Test it out ‹/›
src attribute sets or returns audio/Current source of the video.
Source is audio/Actual location of the video file (URL)
IEFirefoxOperaChromeSafari
Internet Explorer 10, Firefox, Opera, Chrome and Safari support the src attribute.
Note:Internet Explorer 9 and earlier versions do not support the src attribute.
Set src attribute:
audio|video.src=URL
Return src attribute:
audio|video.src
Value | Description |
---|---|
URL | Specified audio/URL of the video source. Possible values:
|
Return value: | String value, the current audio/Video Source. |
---|