【问题标题】:Uncaught ReferenceError未捕获的引用错误
【发布时间】:2013-04-05 03:23:56
【问题描述】:

我正在尝试使用 HTML5 中的 onEnded 属性一首一首地播放 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>

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

【问题讨论】:

  • 你应该使用 song.setAttribute("src", "countdown.wav");
  • 另外song 没有attr 方法。

标签: javascript html referenceerror


【解决方案1】:

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

使用 jQuery 对象

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

使用 DOM 对象

song.src = "countdown.wav";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-27
    • 2014-10-11
    • 2018-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多