用于计算按钮点击次数的Javascript代码 [英] Javascript code to count number of clicks on a button
本文介绍了用于计算按钮点击次数的Javascript代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个页面,我想计算按钮的点击次数。并且数字显示在该按钮的正下方。
I have a page where i want to count the number of clicks on a button. and the numbers are shown just below that button.
我试图搜索并找到了这个。我认为这不会计算总点击次数:
保持跟踪按钮点击次数
I tried to search and found this. I think this will not count the total number of clicks: Keeping track of number of button clicks
我熟悉javascript代码,所以任何帮助都会有用。
I am familiar with javascript code, so any help would be useful.
推荐答案
假设你的html是:
<div id="showCount"></div>
<input type="button" id="btnClick" value="Click me" onclick="CountFun();/>
现在功能是:
<script>
var cnt=0;
function CountFun(){
cnt=parseInt(cnt)+parseInt(1);
var divData=document.getElementById("showCount");
divData.innerHTML="Number of Downloads: ("+cnt +")";//this part has been edited
}
</script>
这篇关于用于计算按钮点击次数的Javascript代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文