jQuery-可变增量+1 [英] jQuery - Variable Increment +1
问题描述
我看了一眼,我有些困惑.
I've had a look round and I'm a little confused.
对于我的特定问题似乎有几种回答,但我并不完全理解.
There seems to be several responses to my particular problem but I don't fully understand.
因此,如果有人可以帮助,那就太好了!
So if anybody could help that'd be great!
基本上,我设置了一个变量
var firstThumb = "02"
并且我想增加它
function thumbIncrease() {
firstThumb++
};
每隔一段时间
setInterval(function(){
getThumb.trigger("click");
thumbIncrease();
}, 5000);
基本上我希望发生的是- 每5秒钟触发一次点击,我希望我的firstThumb变量增加1.
Basically what I expect to happen is - Every 5 seconds a click is triggered, and I want my firstThumb variable to increase by 1.
所以02,单击,03,单击,04,单击....
So 02, click, 03, click, 04, click....
因此,每次单击不同的元素.
So each time it clicks a different element.
任何帮助都会很棒!
谢谢!
编辑
感谢您的答复!我现在明白了!因此,我得到0的原因,对我而言,比对代码而言更重要.我目前有15件事需要点击. 01和15是2个字符,这意味着我的代码看起来更整洁.我应该手动删除0吗?还是有更好的方法呢?
Thanks for the responses! I kind of understand now! So the reason I've got a 0, is more for me than for the code. I currently have 15 things that I need clicking. 01 and 15 being 2 characters, meaning my code looks neater. Should I just man up and remove the 0? Or is there a better way of doing it?
推荐答案
var counter = 1;
setInterval(function() {
var _text = counter + "<br>";
$("div").append(_text);
counter++;
},5000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div>
</div>
如果要替换旧数字,请使用.html()
代替.append()
If you want it to replace the old number use .html()
instead of .append()
"01"
是字符串,1
是可以递增的数字.
"01"
is a string, 1
is a number you can increment.
这篇关于jQuery-可变增量+1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!