【发布时间】:2014-10-03 15:17:15
【问题描述】:
我的网页有一个点击计数器 onclick 效果,当我点击它时,会显示一条文字
您点击了按钮 - ??? - 次(???将是点击量)
onclick 效果很好,但我想知道是否可以更改结果的显示。你看,我希望它不是“你点击了按钮”,而是有一个图片的缩影版本,所以就像
miniature_image - ???
如果这完全可以理解的话。
这是我当前的按钮脚本
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 的数量会发生变化。
如果您认为这会有所帮助,可以通过我的 * 个人资料上的链接查看我的网页。
提前感谢大家!
【问题讨论】:
-
您能否将您的代码作为小提琴之类的东西,以便我们可以现场试用
-
我现在要尝试制作一个,虽然上次我尝试将我的脚本放入 HTML5 中,但它没有显示任何内容。我会尽快发布链接
-
jsfiddle.net/b6ttzq7z 我做了鼠标悬停的音效,但是关于点击效果,我不能让它起作用。但这就是我所管理的。希望对你有所帮助
标签: javascript html image onclick click-counting