Track src 属性

定义和用法

src 属性设置或返回轨道的 src 属性的值。

HTML src 属性规定轨道文件的 URL。

另请参阅:

HTML 参考手册:HTML <track> src attribute

实例

例子 1

获取轨道文件的 URL:

var x = document.getElementById("myTrack").src;

x 的结果可能是:

https://www.codew3c.com/jsref/subtitles_en.vtt

例子 2

更改轨道文件的 URL:

document.getElementById("myTrack").src = "subtitles_no.vtt";

语法

返回 src 属性:

trackObject.src

Set src attribute:

trackObject.src = URL

Attribute value

Value Description
URL Specifies the URL of the track file.

Technical details

Return value: String value, representing the URL of the track file. Returns the entire URL, including the protocol (such as http://).

Browser support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Supported 10.0 Not supported Not supported Supported