我们的志愿者还没有将这篇文章翻译为 中文 (简体)加入我们帮助完成翻译
您也可以阅读此文章的English (US)版。

The HTMLSourceElement interface provides special properties (beyond the regular HTMLElement object interface it also has available to it by inheritance) for manipulating <source> elements.

Properties

Inherits properties from its parent, HTMLElement.

HTMLSourceElement.keySystem
Is a DOMString describing the key system encrypting the stream.
HTMLSourceElement.media
Is a DOMString reflecting the media HTML attribute, containing the intended type of the media resource.
HTMLSourceElement.sizes
Is a DOMString representing image sizes between breakpoints
HTMLSourceElement.src
Is a DOMString reflecting the src HTML attribute, containing the URL for the media resource. The HTMLSourceElement.src property has a meaning only when the associated <source> element is nested in a media element that is a <video> or an <audio> element. It has no meaning and is ignored when it is nested in a <picture> element. 
Note: If the src property is updated (along with any siblings), the parent HTMLMediaElement's load method should be called when done, since <source> elements are not re-scanned automatically.
HTMLSourceElement.srcset
Is a DOMString reflecting the srcset HTML attribute, containing a list of candidate images, separated by a comma (',', U+002C COMMA). A candidate image is a URL followed by a 'w' with the width of the images, or an 'x' followed by the pixel density.
HTMLSourceElement.type
Is a DOMString reflecting the type HTML attribute, containing the type of the media resource.

Methods

No specific method; inherits methods from its parent, HTMLElement.

Specifications

Specification Status Comment
Encrypted Media Extensions
The definition of 'HTMLSourceElement' in that specification.
Recommendation Added the keySystem attribute.
HTML Living Standard
The definition of 'HTMLSourceElement' in that specification.
Living Standard No change from HTML5.
HTML5
The definition of 'HTMLSourceElement' in that specification.
Recommendation Initial definition.

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support Yes Yes3.59 Yes Yes
keySystem Yes Yes Yes1 ? ? ?
media Yes Yes3.59 Yes Yes
sizes Yes Yes

38

332

? ? ?
src Yes Yes3.59 Yes Yes
srcset Yes Yes

38

332

? ? ?
type Yes Yes3.59 Yes Yes
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support Yes Yes Yes4 Yes Yes ?
keySystem Yes Yes Yes Yes1 ? ? ?
media Yes Yes Yes4 Yes Yes ?
sizes Yes Yes Yes

38

332

? ? ?
src Yes Yes Yes4 Yes Yes ?
srcset Yes Yes Yes

38

332

? ? ?
type Yes Yes Yes4 Yes Yes ?

1. This feature is behind the media.eme.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

2. From version 33: this feature is behind the dom.image.picture.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

See also

文档标签和贡献者

最后编辑者: fscholz,