2009-08-14 7 views
2

Ceci est probablement très simple!Liste séquentielle jQuery Problème

J'ai suivi un tutoriel de http://webdesignerwall.com/demo/jquery-sequential/jquery-sequential-list.html

Il fonctionne très bien quand il y a une liste d'utilisation sur la page. Mais quand il y a 2 listes ol J'ai un problème:

$(document).ready(function(){ 

    $("ol.step li").each(function (i) { 
     i = i+1; 
     $(this).prepend('<span class="stepnumber"> Step '+i+'</span>'); 
    }); 

}); 


<ol class="step"> 
    <li>something</li> 
    <li>something</li> 
    <li>something</li> 
</ol> 

<ol class="step"> 
    <li>something</li> 
    <li>something</li> 
    <li>something</li> 
</ol> 

Quand j'ai plus d'un ol les étapes continuer, traversant dans la prochaine ol comme ceci:

- commencer ol ---

Étape 1 - quelque chose

Étape 2 - quelque chose

Étape 3 - quelque chose

- ol final -

- commencer ol -

Étape 4 - quelque chose

Étape 5 - quelque chose

Étape 6 - quelque chose

- ol final - -

J'ai besoin qu'il soit: 1,2,3 puis recommence à 1,2,3 pour le suivant NON 1,2,3,4,5,6!

Quelqu'un peut-il aider?

Merci pour la réponse rapide!

Répondre

9

Vous devez traiter chaque liste séparément. Quelque chose comme:

$(document).ready(function(){ 
    $("ol.step").each(function() { 
     var i = 1; 
     $(this).children().each(function() { 
      $(this).prepend('<span class="stepnumber"> Step '+i+'</span>'); 
      i++; 
     }); 
    }); 
});