Javascript自动播放声音文件,单击其中一个按钮时停止

时间:2012-07-30 09:07:00

标签: javascript html audio autostart

所以我有一些按钮,人们可以按下来听音频文件。当然,音频文件不能“重叠”,因为那将是一团糟。这有效,但现在我想在网站加载时自动播放其中一个文件,但仍然保持每当我按下另一个按钮时它就会停止的事实。

这是我到目前为止所得到的:

目:

<script language="javascript" type="text/javascript">
 function playSound(soundfile) {
 document.getElementById("dummy").innerHTML=
 "<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"false\" loop=\"true\" />";
 }
 </script>

体:

<span id="dummy"></span>

<p style="text-align:center;">
<a href="#" onclick="playSound('Sound1.mp3');"> 
<img class="alignnone" width="128" img src="Img1.png" ></a>

<a href="#" onclick="playSound('Sound2.mp3');"> 
<img class="alignnone" width="128" img src="Img2.png"  ></a>

<a href="#" onclick="playSound('Sound3.mp3');"> 
<img class="alignnone" width="128" img src="Img3.png"  ></a>
</p>

1 个答案:

答案 0 :(得分:0)

试试这个jquery解决方案:

http://archive.plugins.jquery.com/project/sound_plugin

我在反应时间测试中成功地使用了这个,我必须在每次测试之前发出声音。

相关问题