好的标题与我搜索的内容匹配,但缩小范围;),
即时寻找要添加到我的网页的数字计数器,我希望数字延伸到无限值,从表中添加数字数据添加到计数器而不会将计数器重置为0。
非常感谢任何有帮助的人:)
<script>
('.myClassAbleToAddOnCounter').bind('click', function(){
var currentCount = parseInt($('#myCounterTotal').html());
var countToAdd = parseInt($(this).html());
('#myCounterTotal').html( currentCount + countToAdd );
});</script>
答案 0 :(得分:0)
如何在 JavaScript ..
中制作计数器的示例function Counter(start) {
this.value = this._initial = start || 0;
}
Counter.prototype.now = function () { return this.value; };
Counter.prototype.inc = function () { return ++this.value; };
Counter.prototype.add = function (x) { return this.value += x; };
Counter.prototype.reset = function () { return this.value = this.initial; };
然后
var c = new Counter();
c.inc(); // 1
c.inc(); // 2
c.add(5); // 7