2012-07-30 41 views
0

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

这是我到目前为止有:

头:

<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> 

回答

相关问题