3
我正在閱讀關於jquery queue()
here。第一個答案是非常全面:使用jquery next()在這個隊列中的功能
var theQueue = $({}); // jQuery on an empty object - a perfect queue holder
$.each([1,2,3],function(i, num) {
// lets add some really simple functions to a queue:
theQueue.queue('alerts', function(next) {
// show something, and if they hit "yes", run the next function.
if (confirm('index:'+i+' = '+num+'\nRun the next function?')) {
next();
}
});
});
// create a button to run the queue:
$("<button>", {
text: 'Run Queue',
click: function() {
theQueue.dequeue('alerts');
}
}).appendTo('body');
// create a button to show the length:
$("<button>", {
text: 'Show Length',
click: function() {
alert(theQueue.queue('alerts').length);
}
}).appendTo('body');
我不明白怎麼next()
(8號線),然而工作。我得到的是,如果我註釋掉「next」確認框不能彈出,直到我再次按下按鈕,但我認爲next()
主要用於遍歷dom。儘管如此,它似乎正在告訴函數再次運行。
此外,如果confirm
框的排隊功能位於each()
功能範圍內,爲什麼它們都會在沒有next()
的情況下成功排隊?
哈哈,好的謝謝:) – 1252748 2013-02-26 06:39:32