我想在单击网站中的某个图像时播放 MP3 文件。我还想隐藏 MP3 文件。我怎样才能做到这一点?我尝试了这段代码,但没有任何反应:
<html>
<body>
<script language="javascript" type="text/javascript">
function playSound(soundfile) {
document.getElementById("dummy").innerHTML=document.getElementById("dummy").innerHTML +
"<embed src=\""+mp3/a/bat.mp3+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
}
<span id="dummy" onclick="playSound('mp3/a/bat.mp3');"><img src="short_a/bat.jpg"
name="Bottom-1" width="115" height="45" border="0" id="Bottom-1"/></a></span>
</script>
</body>
</html>
这不是关于PHP
,你只需添加HTML
代码到你的PHP
page.
如果您坚持使用嵌入标签,这里就是您想要的代码,DEMO http://jsfiddle.net/zHfrP/
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function playSound(el,soundfile) {
var embed = document.getElementById("embed");
if (!embed) {
var embed = document.createElement("embed");
embed.id= "embed";
embed.setAttribute("src", soundfile);
embed.setAttribute("hidden", "true");
el.appendChild(embed);
} else {
embed.parentNode.removeChild(embed);
}
}
</script>
</head>
<body>
<span id="dummy" onclick="playSound(this, 'https://dl.dropbox.com/u/39640025/MP3/Waves.mp3');">
<img src="short_a/bat.jpg" name="Bottom-1" width="115" height="45" border="0" id="Bottom-1"/>
</span>
</body>
</html>
不过我建议你使用 Audio API,DEMO http://jsfiddle.net/zHfrP/1/
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function playSound(el,soundfile) {
if (el.mp3) {
if(el.mp3.paused) el.mp3.play();
else el.mp3.pause();
} else {
el.mp3 = new Audio(soundfile);
el.mp3.play();
}
}
</script>
</head>
<body>
<span id="dummy" onclick="playSound(this, 'https://dl.dropbox.com/u/39640025/MP3/Waves.mp3');">
<img src="short_a/bat.jpg" name="Bottom-1" width="115" height="45" border="0" id="Bottom-1"/>
</span>
</body>
</html>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)