2013-02-03 43 views
0

我會嘗試讓代碼在這裏說明自己:如果條件可以用來檢查當前代碼之後是否會有另一個迭代?檢測是否有下一個,而在每個循環中

$('#%id% td').each(function(){ 
if(??????????){      // if there will be a next iteration 
while($(this).height() == thisheight){ 
    // do something here on this iteration, but only if there will be another. 
} 
} 
}); 
+0

如果這是'each'循環的整個內容,可以通過選擇器輕鬆解決。 –

回答

2

因爲它似乎要每一個元素,但最後一個過程中,你可以簡單地從該組刪除最後一個元素,.slice[docs]

$('#%id% td').slice(0, -1).each(function() { 
    // no need for `if` statement here 
    // ... 
}); 

回答你原來的問題是將當前迭代與元素數進行比較:

var $elements = $('#%id% td'); 
var max = $elements.length - 1; 

$elements.each(function(index) { 
    if (index < max) { 
     // ... 
    } 
    // ... 
}); 
+0

Persect ..!我將用.next()函數包裝起來,以便在.each()循環之外進行思考。謝謝。 –

+0

'$('#%id%td:not(:last)')'是否有效? –

+0

@Jan:我認爲是的,是的。 –

相關問題