未捕获的引用错误
Posted
技术标签:
【中文标题】未捕获的引用错误【英文标题】: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
方法。
【参考方案1】:
您应该将attr() 与 jQuery 元素一起使用,但您与 DOM 对象一起使用时,如果 src
不是变量,也应将其括在引号中。
使用 jQuery 对象
$(song).attr('src',"countdown.wav");
使用 DOM 对象
song.src = "countdown.wav";
【讨论】:
以上是关于未捕获的引用错误的主要内容,如果未能解决你的问题,请参考以下文章