문제

I am attempting to play 3 songs, one after another by using the onEnded attribute in HTML5. Here is my first attempt, but I'm getting an error.

Error : Uncaught ReferenceError: src is not defined nextSong marioKart.html:49 onended marioKart.html:58

Below is my code:

<script>
function nextSong(){
    var song = document.getElementById("player");
    song.attr(src,"countdown.wav");
}
</script>
</head>

<body>
<div style="position:relative">
<audio controls autoplay="true" onEnded="nextSong()" onplay="race()" >
     <source id="player" src="startMusic.wav" type="audio/mpeg" />
</audio>

Can someone help me in achieving this ?

도움이 되었습니까?

해결책

You should use attr() with jQuery element but you are using with DOM object also enclose src in quotes if it is not variable.

Using jQuery object

$(song).attr('src',"countdown.wav");

Using DOM object

song.src = "countdown.wav";
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top