开发者

How to use loop action in Jquery?

I am developing a CRUD application using DWR & Jquery. I want to display the table records from database. I wa开发者_如何转开发nt to put a loop to do that. While searching for that, i ve came across each() method in Jquery. I cant get its exact concept. Any idea, or solution??


There are two types of .each() method in jQuery.

The first is a method of every jQuery object and iterates over the object, which usually contains an array of DOM elements. An example would be:

$('.someClass').each(function(i,val) {
    // "i" references the current index in the iteration
    // "val" references the value (normally DOM element) stored in the jQuery object.
 });
  • http://api.jquery.com/each/

The other type is more generic. It is meant to iterate over any type of collection. It is equivalent to a javascript for() loop.

$.each(array, function(i,val) {
    // "i" references the current index in the iteration
    // "val" references the value at that index of the collection.  
});

With $.each() you could iterate over a javascript object, or other types of collections like a NodeList or a jQuery object.

It is what jQuery calls internally when you use the first .each() version noted at the top.

  • http://api.jquery.com/jquery.each/


The each function allows you to iterate over each element that matches the selector used. You can see an example in the jquery documentation.


jQuery's each() method is used to iterate through the contents of a jQuery object. In your case I think you would just want to use a simple JavaScript 'For Loop' and append() an element containing the record's information each time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜