Javascript 未捕获引用错误

Javascript 未捕获引用错误,javascript,html,referenceerror,Javascript,Html,Referenceerror,我正在尝试播放3首歌曲,通过使用HTML5中的oneded属性一首接一首地播放。这是我的第一次尝试,但我得到了一个错误 错误:未捕获引用错误:未定义src nextSong marioKart.html:49 onended marioKart.html:58 下面是我的代码: <script> function nextSong(){ var song = document.getElementById("player"); song.attr(src,"count

我正在尝试播放3首歌曲,通过使用HTML5中的
oneded
属性一首接一首地播放。这是我的第一次尝试,但我得到了一个错误

错误:
未捕获引用错误:未定义src
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>

函数nextSong(){
var song=document.getElementById(“播放器”);
song.attr(src,“countdown.wav”);
}
有人能帮我实现这一点吗?

您应该与jQuery元素一起使用,但是您正在与DOM对象一起使用,如果它不是变量,还可以将
src
括在引号中

使用jQuery对象

使用DOM对象


您应该使用song.setAttribute(“src”、“countdown.wav”);另外,
song
没有
attr
方法。
$(song).attr('src',"countdown.wav");
song.src = "countdown.wav";