【发布时间】:2019-06-01 17:38:23
【问题描述】:
在我的代码中,我想设置音频元素的属性值,以便在音频文件停止播放时将段落元素中的“测试”更改为“工作”。
我知道我可以在脚本之外创建音频元素,但我需要这个来做其他事情。
“horse.mp3”文件在那里是因为我在这个页面上玩弄试图让它工作:https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_audio
<!DOCTYPE html>
<html>
<body>
<p id="test">testing</p>
<script>
var audio = new Audio("horse.mp3");
audio.setAttribute("onended", "function(){document.getElementById("
test ").innerHTML = "
working "}");
audio.play();
</script>
</body>
</html>
【问题讨论】:
-
你的调试控制台有错误
标签: html audio setattribute