I've set up a test page to demonstrate this, which can be viewed at https://dl.dropboxusercontent.com/u/846812/html_audio_test/audio_test.html
The page source is
<!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>
When i validate this at http://validator.w3.org/check it complains:
Error Line 9, Column 128: Attribute type not allowed on element audio at this point.
But, i'm following the documentation here: http://www.w3schools.com/html/html5_audio.asp
So, why is it complaining? Have I not properly defined my page as an html5 document?
I'm answering this myself for the benefit of anyone else who's as confused as i clearly was (Nigel Tufnel?) - this is the valid way to do it, and how to play the audio on demand with 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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.