我的网页有一个点击计数器 onclick 效果,当我点击它时,会显示一条文字
你点击了按钮 - ??? - 次(???将是点击量)
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>
我已经尝试用图像源替换“您已单击按钮”部分。像这样
document.getElementById("result").innerHTML="<center><img src="poopamount">"+ localStorage.clickcount + "</center>";
但这只会导致按钮 onclick 效果消失。我也尝试过使用 document.GetElementById("image"),但这也不起作用(但不确定我是否正确设置)
如何在点击量前面添加图片?我需要它成为结果的一部分,因为正如您从我的脚本中看到的那样,它是居中的,并且仅仅定位图片是行不通的,因为 digits 的数量会发生变化。
如果您认为有帮助,可以在我的 stackoverflow 个人资料上的链接上查看我的网页。
提前感谢大家!