我可以在HTML5&LT多个SRC属性;音频>元件?或src属性和<信源>元件? [英] Can I have multiple src attributes in an HTML5 <audio> element? Or an src attribute and a <source> element?

查看:192
本文介绍了我可以在HTML5&LT多个SRC属性;音频>元件?或src属性和<信源>元件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道这是什么意思的<音频> 元素可以有一个的src 属性,或者一个或多个<信源方式> 元素的内容。

I was wondering what does it mean that the <audio> element can have an src attribute, or one or more <source> elements for its contents.


  • 我可以拥有两个或更多的的src 属性?如果是这样,怎么样?

  • 我可以有一个的src 属性的的一个&lt;信源&GT; 元素?

  • Can I have two or more src attributes? If so, how?
  • Can I have an src attribute and a <source> element?

下面是链接到什么我谈论:的http:// dev.w3.org/html5/markup/audio.html#audio

Here is the link to what I'm talking about: http://dev.w3.org/html5/markup/audio.html#audio

有人能详细解释这样对我?

Can someone explain this to me in detail?

推荐答案

这几样在HTML5的问题,总是有两部分组成:它是有效的,会发生什么,如果我做吧。

These kind of questions in HTML5, always have two parts: Is it valid, and what happens if I do it anyway?

1。它是有效的?

没有。虽然链接标记语言参考似乎没有帮助的,因为它省略了关键事实。 (见下文)。

No. Although the link to the markup language reference doesn't seem helpful, since it omits a critical fact. (see below).

相反,我们看看音频元素实际规格。

Instead, look at the actual spec for the audio element.

该内容模型说:

如果该元素具有src属性:零个或多个轨道
  元素,则透明,但与
  没有媒体元素后裔。

If the element has a src attribute: zero or more track elements, then transparent, but with no media element descendants.

如果该元素不具有src属性:一个或多个源
  元素,那么零个或多个轨道
  元素,则透明,但与
  没有媒体元素后裔。

If the element does not have a src attribute: one or more source elements, then zero or more track elements, then transparent, but with no media element descendants.

因此​​,源元素没有特别调出当src属性为present被允许。

So the source element is not specifically called out as being allowed when the src attribute is present.

不过,关于透明位是什么?好,这意味着属于该音频元素的父内部有效元件也音频元素内有效。因此,如果源元素是在父元素有效,那么它也将是音频元素内有效,即使音频元件有src属性。

But what about the "transparent" bit? Well, that means that elements that are valid inside the parent of the audio element are also valid inside the audio element. So if the source element was valid in the parent element, then it would also be valid inside the audio element, even if the audio element had a src attribute.

这可能吗?如果我们检查规格为源元素我们看到在可使用的该元素的上下文

Is that possible? If we check the spec for the source element we see that the context in which the element can be used is

作为一个媒体元素的子元素,前
  任何流量的内容或曲目元素。

As a child of a media element, before any flow content or track elements.

因此​​,音频元素的父将需要即℃的媒体元素;视频&GT; &LT;音频&GT;

So the parent of the audio element would need to be a media element i.e. <video> or <audio>.

不过回到了音频单元(见上文)的内容模型的定义,它说,声音不能有媒体元素的后代 - 因此一个音频元素不能被嵌套在另一个音频元素中。 video元素类似地定义,所以&LT ;源&GT; 不能是℃的有效子;音频方式&gt;通过音频元素的内容模型的透明的一部分

However back at the definition of the content model of the audio element (see above), it says that audio cannot have media elements descendants - so an audio element cannot be nested inside another audio element. The video element is defined similarly, so <source> cannot be a valid child of <audio> via the "transparent" part of the content model of the audio element.

因此​​,既具有的src 属性的音频元素和&lt;信源方式&gt; 儿童不能有效的

Hence, an audio element with both a src attribute and <source> children cannot be valid.

(请注意,您链接到标记语言参考页没有提到任何媒体元素后代的限制,因此,我不认为正确的验证可以由它来决定做的。)

(Note that the Markup Language Reference page you link to doesn't mention the no media element descendants restriction, therefore I don't believe that the correct validation can be determined from it.)

2。如果我这样做也无妨,会发生什么?

这是略为简单。对于对媒体元素的src属性说:

This is somewhat simpler. The spec for the src attribute on media elements says:

有指定媒体两种方式
  资源,src属性,或源
  元素。属性覆盖
  元素。

There are two ways to specify a media resource, the src attribute, or source elements. The attribute overrides the elements.

在换句话说,如果在的src 属性是present,任何&lt;信源&GT; 元素简单地忽略。

In other words, if the src attribute is present, any <source> elements are simply ignored.

请参阅多的事情的src 属性伊恩·博伊德的答案。

See Ian Boyd's answer on the matter of multiple src attributes.

这篇关于我可以在HTML5&LT多个SRC属性;音频&GT;元件?或src属性和&lt;信源&GT;元件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆