我有這個代碼,在按鈕上按下它播放聲音,我想要的是當一個聲音從第一次點擊播放時,如果你點擊另一個按鈕之前,它停止第一個和播放下一個你點擊。Javascript播放聲音點擊,第二個按鈕單擊停止第一個聲音
任何想法都會很棒。
<!DOCTYPE html>
<head>
<title>Sounds</title>
</head>
<body>
<audio id="sound1" src="sounds/sound1.mp3"></audio>
<audio id="sound2" src="sounds/sound2.mp3"></audio>
<button onclick="document.getElementById('sound1').play()">Sound 1</button><br />
<button onclick="document.getElementById('sound2').play()">Sound 2</button><br />
</body>
</html>
在此先感謝。