我已经成功地为我的点击计数器图像添加了 onclick 音频效果,但我想知道,有没有办法随机选择声音,而不是一个声音?当我单击我的图像时,会出现单击图像的次数,并播放声音,但我希望它在每次单击时播放不同的(随机)音频文件(来自我的选择)
这些是到目前为止我的按钮的脚本
Javascript
function clickCounter(){
var audio = document.getElementById("audio");
audio.play();
if(typeof(Storage)!=="undefined"){
if (localStorage.clickcount)
{
localStorage.clickcount=Number(localStorage.clickcount)+1;
}
else
{
localStorage.clickcount=1;
}
document.getElementById("result").innerHTML="<center><b>You have clicked the poop
</b>"+ localStorage.clickcount + "<b> times!</b></center>";
}
else{
document.getElementById("result").innerHTML="I'm sorry to inform you that your browser
does not support this web storage... I guess you could say that your browser is...
shit! awwww yeaahh!";
}
cursor: pointer;
}
HTML
<center>
<font face="chiller" color="#603913" "font size="300" <align="center"><b>Click the
poop!</b>
</center>
<center>
<p><picture onclick="clickCounter()"><picture
onmouseover="document.getElementById('touch').play()"><img src="poop.png"></button></p>
</center>
<audio id="audio" src="fart-01.wav"></audio>
<audio id="touch" src="sticky goo.wav"></audio>
<div id="result"></div>
我将如何编写这个脚本?我知道我必须将它与我当前的 onclick 函数交织在一起,而且我必须制作一个表格,可能带有 tr 或 td 标签。有人可以帮我吗?我不能让它工作。
提前感谢大家!