我有一个问题,因为我不明白这一点。
我想在用 jquery 显示下一个选项卡和编码如下之间等待:
$('#tabs ul .ui-corner-top').each(function(){
setTimeout(function(){},2000)
$(this).children('a').click();
});
如果单击下一个选项卡,我预计会看到等待 2 秒。
但超时仅开始一次,所有 href 都会立即单击,无需等待。
然后我尝试了不同的方法:
for (i=0;i<$('#tabs ul .ui-corner-top').size();i++) {
setTimeout('changeTab(i)',i*3000);
}
function changeTab(i) {
clearTimeout(timeout);
timeout=setTimeout(function(){
$('#mainContent').masonry();
}, 1500);
tablink='a[href*="#tabs-'+i+'"]';
$(tablink).click();
}
超时在这里起作用,但我不知道为什么。这里我只剩下立即点击的问题。它不会等到单击下一个选项卡。
有人可以帮忙吗?
预先感谢
我完全写了奇怪的东西..抱歉...这是我的实际代码,它几乎可以工作:
for (i=0;i<$('#tabs ul .ui-corner-top').size();i++) {
tablink='a[href*="#tabs-'+i+'"]';
setTimeout('changeTab(tablink)',i*3000);
}
function changeTab(tablink) {
$(tablink).click();
}
但他只单击第三个选项卡(#tabs-2)3次,而不是每个选项卡一次(1,2, 3)如我所愿。解释一下:我想在选项卡(jquery ui 选项卡)之间自动切换,并等待下一次单击。
I have a question because i don't understand this.
I want to wait between showing the next tab with jquery and coded something like this:
$('#tabs ul .ui-corner-top').each(function(){
setTimeout(function(){},2000)
$(this).children('a').click();
});
I've expected to see waiting for 2 sec if the next tab will be clicked.
But the Timeout is only starting once and all hrefs are immediate clicked without waiting.
Then I tried something different:
for (i=0;i<$('#tabs ul .ui-corner-top').size();i++) {
setTimeout('changeTab(i)',i*3000);
}
function changeTab(i) {
clearTimeout(timeout);
timeout=setTimeout(function(){
$('#mainContent').masonry();
}, 1500);
tablink='a[href*="#tabs-'+i+'"]';
$(tablink).click();
}
The timeout is working here, but I don't know why. Here I only have the problem left with the immediate clicking. It is not waiting until clicking the next tab.
Can somebody Help?
thanks in advance
i totally wrote weird stuff.. sorry... this is my actual code and its working almost:
for (i=0;i<$('#tabs ul .ui-corner-top').size();i++) {
tablink='a[href*="#tabs-'+i+'"]';
setTimeout('changeTab(tablink)',i*3000);
}
function changeTab(tablink) {
$(tablink).click();
}
But he is only clicking the third tab (#tabs-2) 3 times, not every tab once (1,2,3) like i want. For explaining it: I want to switch automatically between tabs (jquery ui tabs) with an interval of waiting until next click.
发布评论
评论(1)
如果我明白你在问什么......你有很多选项卡,你想用计时器来完成,但是你的查询太贪婪了。
您要做的就是让您的集合以不同的偏移量调用它们中的每一个。
便宜地,您可以做这样的事情...
您必须记住,JQuery 返回与您的查询匹配的结果数组,并且计时器不是按顺序初始化的。当您定义计时器声明时,它会立即开始倒计时。您只是要求 JQuery 为要同时激活的每个结果启动一个计时器。
If I understand what you are asking... you have a number of tabs that you want to progress through with a timer, however your query is being too greedy.
What you will want to do is take your collection invoke each of them with a different offset.
Cheaply, you could do something like this...
You must remember that JQuery returns an array of results that match your query, AND that timers are not sequentially initialized. A timer declaration starts counting down immediately when you define it. You've merely asked JQuery to start a timer for each result to be activated at the same time.