Javascript HTML5 getElementById不';不能使用Firefox

Javascript HTML5 getElementById不';不能使用Firefox,javascript,html,Javascript,Html,我确信过去我访问过音频元素,我知道这是一种有效的使用方式。但是我不明白为什么这次它不起作用!!!我做错了什么?(我正在使用firefox) 调用以下代码有什么问题 <html> <head> <script> <!-- var audio = new Audio(); audio.src = 'sounds/audio1_1.mp3'; audio.controls = true; audio.loop = true; audio.autoplay =

我确信过去我访问过音频元素,我知道这是一种有效的使用方式。但是我不明白为什么这次它不起作用!!!我做错了什么?(我正在使用firefox)

调用以下代码有什么问题

<html>
<head>
<script>
<!-- var audio = new Audio(); audio.src = 'sounds/audio1_1.mp3'; audio.controls = true; audio.loop = true; audio.autoplay = true; -->
var audioElement_theme;
audioElement_theme = document.getElementById("audio1_1");
audioElement_theme.play();
</script>
</head>
<body>
<audio id="audio1_1"><source src="sounds/audio1_1.ogg" type="audio/ogg" /><source src="sounds/audio1_1.mp3" type="audio/mpeg" />Your browser does not support the audio element.</audio>
<div id="mp3_player">
  <div id="audio_box"></div>
  <canvas id="analyser_render"></canvas>
</div>
</body>
</html>
致:


它工作

在您尝试通过其id获取元素时,该元素不存在

移动脚本,使其位于音频元素之后


脚本中还有一个HTML注释。这也可能会造成干扰

JavaScript注释如下所示:

// like this


你的代码有效,我测试过了。当您运行当前代码时,它会在控制台窗口中给您一个错误,如“无法读取null的property.paly()”,因此请将脚本移动到音频标记之后。因此,只需将代码移到标记之后。

不,流行的JS引擎支持HTML注释(尽管这不是标准所要求的)。我的意思是代码绝对正确,但放在了错误的位置。
var audio = new Audio(); 
audio.src = 'sounds/audio1_1.mp3'; 
audio.controls = true; 
audio.loop = true; 
audio.autoplay = true; 
// like this
/* like this */