gpt4 book ai didi

javascript - 在Wordpress网站上点击图片播放随机声音?

转载 作者:行者123 更新时间:2023-12-03 02:21:24 25 4
gpt4 key购买 nike

好的,所以我已经研究了几个小时,在这一点上,我可能只是让自己更加困惑。 ;)

我在这里阅读了该问题的答案:How can I play a random sound on click in a web page?

我还阅读了该作者最初引用的源代码。

我在Wordpress网站的header.php文件中的标记之间添加了以下代码:

 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script>
function playSounds() {
var sounds = new Array(
"http://www.faenathara.com/laughs/Natharalaugh1.wav",
"http://www.faenathara.com/laughs/Natharalaugh2.wav",
"http://www.faenathara.com/laughs/Natharalaugh3.wav",
"http://www.faenathara.com/laughs/Natharalaugh4.wav"
);

$("#element").html("<embed src=\""+sounds[Math.floor(Math.random()*(sounds.length+1))]+"\" hidden=\"true\" autostart=\"true\" />");
}
</script>

然后将其添加到我的 body 标签中:
onload="javascript:playSound()"

而这在我的 body 标签之间:
<div id="element">
<button onclick="playSound()">LAUGH</button>
</div>

我知道我遗漏了一些非常明显的东西,但是我想我已经看了很久了,以至于看不到它是什么。救命?

最佳答案

如果您打算在网页上使用声音-那么我真的建议您使用Soundmanager库。绝对可以消除使用页面声音的所有麻烦。

然后在按钮单击上添加声音非常简单!

关于javascript - 在Wordpress网站上点击图片播放随机声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12121055/

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