?
This document uses PHP Chinese website manual Release
通用遍歷方法,可用于遍歷對象和數(shù)組。
不同于例遍 jQuery 對象的 $().each() 方法,此方法可用于例遍任何對象?;卣{(diào)函數(shù)擁有兩個參數(shù):第一個為對象的成員或數(shù)組的索引,第二個為對應(yīng)變量或內(nèi)容。如果需要退出 each 循環(huán)可使回調(diào)函數(shù)返回 false,其它返回值將被忽略。
object:需要例遍的對象或數(shù)組。
callback:每個成員/元素執(zhí)行的回調(diào)函數(shù)。
例遍數(shù)組,同時使用元素索引和內(nèi)容。
$.each( [0,1,2], function(i, n){ alert( "Item #" + i + ": " + n ); });
例遍對象,同時使用成員名稱和變量內(nèi)容。
$.each( { name: "John", lang: "JS" }, function(i, n){ alert( "Name: " + i + ", Value: " + n ); });