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

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

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

一键显示所有这些。我该如何解决?

最佳答案

您可以像这样一一显示段落:

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++;
  }

});

关于javascript - JQuery:如何在每次点击中一一显示段落标记数组?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37032877/

10-12 15:49