单个页面上的多个音频文件javascript

mulitiple audio files javascript on single page

本文关键字:音频 文件 javascript 单个页      更新时间:2023-09-26

所以我找到了一个快速音频播放按钮的代码片段https://siongui.github.io/2012/10/12/javascript-toggle-sound-onclick/.我想合并多个音频文件,但在页面加载时,我创建的音频按钮只播放最后一个音频文件。 enter code here播放音频您的浏览器不支持此音频格式。

<script type="text/javascript">
function toggleSound() {
  var audioElem = document.getElementById('creditCardFem');
  if (audioElem.paused)
    audioElem.play();
  else
    audioElem.pause();
}
function toggleSoun() {
  var audioCreditM = document.getElementById('creditCardMa');
  if (audioCreditM.paused)
    audioCreditM.play();
  else
    audioCreditM.pause();
}
</script>
<div class="audioPlayer">
<button id="player" type="button"
  onclick="javascript:toggleSound();">
  Play Audio
</button>
<audio id="creditCardFem">
  <source src="http://www.smartaction.com/wp-content/uploads/2015/06/Financial_Services_Credit_Card_Payment_Female_Inbound.mp3" type="audio/mpeg" type="audio/mpeg">
Your browser does not support this audio format.
</audio>
</div>
<div class="audioPlayer">
<button id="player" type="button"
  onclick="javascript:toggleSoun();">
  Play Audio
</button>
<audio id="creditCardMa">
  <source src=#">
Your browser does not support this audio format.
</audio>
</div>

在这段代码中似乎只有一个音频文件被链接到。

<audio id="creditCardMa">在其<source src="#">子代中没有引用。