<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<audio src="bg.mp3" controls id="audio"> 您的浏览器不支持 </audio>
<button onclick="foo()">播放/暂停</button>
<script>
var audio = document.getElementById('audio');
function foo() {
if (audio.paused) {
audio.play()
}else{
audio.pause();
}
}
</script>
</body>
</html>
注意区分 audio.pause() audio.paused