jQuery récupère les atsortingbuts source img de la liste et les place dans un tableau

J’ai cette liste de miniatures et voudrais insérer les chemins de l’image (sources) dans un tableau: tn_array

  • fourth caption
  • fifth caption
  • sixth caption

Vous pouvez créer le tableau d’atsortingbuts src plus directement en utilisant map() :

 var tn_array = $("#thumbnails img").map(function() { return $(this).attr("src"); }); 

Edit: tn_array est un object ici plutôt qu’un tableau Javascript ssortingct, mais il agira comme un tableau. Par exemple, c’est le code légal:

 for (int i=0; i 

Vous pouvez cependant appeler get() , ce qui en fera un tableau ssortingct:

 var tn_array = $("#thumbnails img").map(function() { return $(this).attr("src"); }).get(); 

Comment faites-vous la différence? Appel:

 alert(obj.constructor.toSsortingng()); 

La première version sera:

 function Object() { [native code] } 

La deuxième:

 function Array() { [native code] } 

Vous pouvez parcourir l’élément img :

 var tn_array = Array(); $('#thumbnails img').each(function() { tn_array.push($(this).attr('src')); });