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>';
}
});
Run Code Online (Sandbox Code Playgroud)
只需单击一下即可显示所有这些内容.我该如何解决?
您可以像这样逐个显示段落:
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++;
}
});
Run Code Online (Sandbox Code Playgroud)