ringa_lee
There is no problem with the code, please check it yourself:
1. Whether the browser supports HTML5
2. Whether the audio file path is correct and whether the audio file format is correct
3. Whether the variables conflict, etc.
It should be a problem with your resources, I have no problem debugging locally
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
var audio = document.createElement('audio');
var source = document.createElement('source');
audio.setAttribute('controls', 'controls');
audio.innerHTML = "您的瀏覽器不支持 audio 標(biāo)簽。";
source.src = './hello.mp3';
source.setAttribute('type','audio/mpeg');
audio.appendChild(source);
document.body.appendChild(audio);
window.addEventListener('click', function(){
audio.play();
});
</script>
</body>
</html>
Run results: (note that the red box is not 0:00)