English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML 参考手册

HTML 标签大全

HTML Audio/视频 DOM src 属性

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 ‹/›

Definition and Usage

src attribute sets or returns audio/Current source of the video.
Source is audio/Actual location of the video file (URL)

Browser Compatibility

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.

Syntax

Set src attribute:

audio|video.src=URL

Return src attribute:

audio|video.src

Attribute value

ValueDescription
URLSpecified audio/URL of the video source.

Possible values:

  • Absolute URL - Points to another website (e.g., src="http:)//www.example.com/movie.ogg"}

  • Relative URL - Points to a file within the website (e.g., src="movie.ogg")

Technical Details

Return value:String value, the current audio/Video Source.
 HTML Audio/Video DOM Reference Manual