音频标签未通过W3C验证 - 为什么?

时间:2015-03-11 15:13:26

标签: html html5 audio w3c-validation

我已经设置了一个测试页面来演示这个,可以查看 https://dl.dropboxusercontent.com/u/846812/html_audio_test/audio_test.html

页面来源是

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>My audio test page</title>
  </head>        

  <body>
    <audio src="https://dl.dropboxusercontent.com/u/846812/html_audio_test/cha-ching.wav" type="audio/wav" id="audio-cha-ching"></audio>
    <p>You should hear a "ka-ching" noise.</p>
    <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
    <script type="text/javascript">
      $(function(){ 
        $("audio")[0].play();
      });
    </script>
  </body>
</html>

当我在http://validator.w3.org/check验证时,它抱怨:

错误第9行,第128列:此时元素音频上不允许使用属性类型。

但是,我正在遵循此处的文档:http://www.w3schools.com/html/html5_audio.asp

那么,为什么抱怨?我没有将我的页面正确定义为html5文档吗?

1 个答案:

答案 0 :(得分:0)

我自己回答这个问题是为了让我感到困惑的其他人的利益(Nigel Tufnel?) - 这是有效的方法,以及如何播放音频需求与jquery。

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>My audio test page</title>
  </head>        

  <body>
    <audio id="audio-cha-ching">
      <source src="https://dl.dropboxusercontent.com/u/846812/html_audio_test/cha-ching.wav" type="audio/wav" >
    </audio>
    <p>You should hear a "ka-ching" noise.</p>
    <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
    <script type="text/javascript">
      $(function(){ 
        $("#audio-cha-ching").trigger("play");
      });
    </script>
  </body>
</html>
相关问题