-
[转自:http://api.jquery.com/jQuery.each/]
-
version added: 1.0
-
jQuery.each( collection, callback(indexInArray, valueOfElement) )
collectionThe object or array to iterate over.
callback(indexInArray, valueOfElement)The function that will be executed on every object.
The$.each()
function is not the same as $(selector).each(), which is used to iterate, exclusively, over a jQuery object. The$.each()
function can be used to iterate over any collection, whether it is a map (JavaScript object) or an array. In the case of an array, the callback is passed an array index and a corresponding array value each time. (The value can also be accessed through thethis
keyword, but Javascript will always wrap thethis
value as anObject
even if it is a simple string or number value.) The method returns its first argument, the object that was iterated.
jQuery AJAX 请求 参见:http://www.w3school.com.cn/jquery/jquery_ajax.asp
请求 | 描述 |
---|---|
$(selector).load(url,data,callback) | 把远程数据加载到被选的元素中 |
$.ajax(options) | 把远程数据加载到 XMLHttpRequest 对象中 |
$.get(url,data,callback,type) | 使用 HTTP GET 来加载远程数据 |
$.post(url,data,callback,type) | 使用 HTTP POST 来加载远程数据 |
$.getJSON(url,data,callback) | 使用 HTTP GET 来加载远程 JSON 数据 |
$.getScript(url,callback) | 加载并执行远程的 JavaScript 文件 |