3

我正在尝试使用onEndedHTML5 中的属性一首一首地播放 3 首歌曲。这是我的第一次尝试,但出现错误。

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

下面是我的代码:

<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>

有人可以帮助我实现这一目标吗?

4

1 回答 1

5

您应该将attr()与 jQuery 元素一起使用,但与 DOM 对象一起使用时,src如果它不是可变的,也应将其括在引号中。

使用 jQuery 对象

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

使用 DOM 对象

song.src = "countdown.wav";
于 2013-04-12T14:33:54.193 回答