![](/img/trans.png)
[英]Trying to iterate through and parse xml tags and display the text inside each one ina paragraph separately
[英]JQuery: How to display an array of paragraph tags one by one on each click?
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++;
}
});
<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;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.