TextTrackList.length - Web APIs 编辑
The read-only TextTrackList
property length
returns the number of entries in the TextTrackList
, each of which is a TextTrack
representing one track in the media element. A value of 0 indicates that there are no text tracks in the media.
Syntax
var trackCount = TextTrackList.length;
Value
A number indicating how many text tracks are included in the TextTrackList
. Each track can be accessed by treating the TextTrackList
as an array of objects of type TextTrack
.
Example
This snippet gets the number of text tracks in the first media element found in the DOM by querySelector()
.
var mediaElem = document.querySelector("video, audio");
var numTextTracks = 0;
if (mediaElem.textTracks) {
numTextTracks = mediaElem.textTracks.length;
}
Note that this sample checks to be sure HTMLMediaElement.textTracks
is defined, to avoid failing on browsers without support for TextTrack
.
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'TextTrackList: length' in that specification. | Living Standard |
Browser compatibility
BCD tables only load in the browser
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论