gpt4 book ai didi

onclick - 单击图像时播放 MP3

转载 作者:行者123 更新时间:2023-12-03 01:58:23 25 4
gpt4 key购买 nike

当我单击站点中的某个图像时,我想播放 MP3 文件。我还希望隐藏 MP3 文件。我怎样才能做到这一点?我尝试了这段代码,但没有任何 react :

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

如果你坚持嵌入标签,这里是你想要的代码,DEMO

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

尽管如此,我还是建议您使用音频 API, DEMO
<!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>

关于onclick - 单击图像时播放 MP3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33816505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com