2016-05-04 7 views

Odpowiedz

6

Można wyświetla akapity jeden po drugim, jak ta:

var sentences = ['sentenceone', 'another sentence', 'another sentence again']; 
var i = 0; 

$(".btn").on('click', function() { 

    if (i < sentences.length) { 
    samplebox.innerHTML += '<p>' + sentences[i] + '</p>'; 
    i++; 
    } 

}); 
0
<button class="btn" data-step="1">Click here</button> 

var sentences = ['sentenceone', 'another sentence', 'another sentence again']; 

$(".btn").on('click', function() { 
     var limit = parseInt($(this).attr("data-step")) - 1; 
     for(var i=0; i < limit; i++) { 
      samplebox.innerHTML += '<p>'+sentences[i]+'</p>'; 
     } 
     $(this).attr("data-step") = limit + 2; 
    }); 
Powiązane problemy