After some attempts based on answers here from colleagues, I had a clear vision, just define two variable with a scope greater to be initialization and another to condition, already the "click counter" is the part. Let’s see the result of this, just below:
var n = 0; // Variável de Inicialização do laço
var i = 0; // Variável de Condição do laço
var j = 0; // Esta é variável que tão somente conta os cliques no botão
function mais() {
// Logo no primeiro clique inicia-se o Salto de 20 em 20 na declaração 2 - condição
i += 20;
// Exibi o(s) número(s) de clique(s) dado(s)
document.getElementById('view').textContent = i;
// Nesta linha iremos quebrar/dividir o(s) dado(s) de cada string
barra = dados.split("|");
for (x = n; x < i; x++) {
if (barra[x]) {
// Logo abaixo exibimos a informação na página de cada string
document.getElementById('list').innerHTML += "<br>" + barra[x] + "<br>";
}
}
// No segundo clique inicia-se o Salto de 20 em 20 na declaração 1 - inicialização
// Isto se faz necessário para que não repita as primeiras linhas exibidas
// mas que de continuidade nas seguintes após as primeiras e assim por diante ...
if (j) {
n += 20
}
}
dados = //Isto é a nosso banco de dados para o nosso exemplo
// O 1º clique - Mostra a listagem 1 do A - E
"|A|Tam.: G|Cod.: 01|" +
"|B|Tam.: M|Cod.: 02|" +
"|C|Tam.: P|Cod.: 03|" +
"|D|Tam.: P|Cod.: 04|" +
"|E|Tam.: G|Cod.: 05|" +
// O 2º clique - Mostra a listagem 2 do F - J
"|F|Tam.: P|Cod.: 06|" +
"|G|Tam.: M|Cod.: 07|" +
"|H|Tam.: P|Cod.: 08|" +
"|I|Tam.: P|Cod.: 09|" +
"|J|Tam.: G|Cod.: 10|" +
// O 3º clique - Mostra a listagem 3 do K - O
"|K|Tam.: G|Cod.: 11|" +
"|L|Tam.: M|Cod.: 12|" +
"|M|Tam.: P|Cod.: 13|" +
"|N|Tam.: P|Cod.: 14|" +
"|O|Tam.: G|Cod.: 15|" +
// O 4º clique - Mostra a listagem 4 do P - T
"|P|Tam.: G|Cod.: 16|" +
"|Q|Tam.: M|Cod.: 17|" +
"|R|Tam.: P|Cod.: 18|" +
"|S|Tam.: P|Cod.: 19|" +
"|T|Tam.: G|Cod.: 20|" +
// O 5º clique - Mostra a listagem 5 do U - Y
"|U|Tam.: G|Cod.: 21|" +
"|V|Tam.: M|Cod.: 22|" +
"|W|Tam.: P|Cod.: 23|" +
"|X|Tam.: P|Cod.: 24|" +
"|Y|Tam.: G|Cod.: 25|";
<center>
<input type="button" onclick="mais(j++)" value="Conta">
<div id="view"></div>
<hr>
<div id="list"></div>
</center>
But why would I have to add/traverse every 20?
I say! - For my purpose as you can analyze I am searching the data from within a method new String()
.
However, I just wanted to show off 5 strings per click.
With each dice between double quotes, we have the bars "|", which in turn makes the division of data, to know are: 4 bars for string.
Knowing this, it multiplies 4 barras
for 5 strings
= 20 linhas
Thus, the var n=0
, n += 20
and the var i=0
, i += 20
to change the declaration 1 and declaration 2 of the loop for
So we have the jump of 20 in 20 lines
NOTE - what I had in mind when I asked this question was creating an effect sroll infinity in Javascript Pure. I realized I could do it with a loop
jutely with the method scrollTop()
. It was in that intention that I came to the conclusion that, not only would it create the effect infinite scroll with this logic, but also, make static paging and randomize the information on the page.
'Cause I couldn’t use the syntax of for
as it is in itself, there would be no way to traverse in sequence (ordinal numbers), of course that’s how a loop does. If I did so, at each click on the button it would return me only the vigesima(last) line of each string
.
is (var i = 10; i < x; i += 10)
– Oralista de Sistemas
Explain the last paragraph better, it is confused. Want to increase the initialization? Try to make sure? What for? Want to increase the condition? Like?
– Maniero
The
i
will have the incremental value of 1 same? Type, will be 20 to 30, but it will go through 21,22,23,24... And so on until 30?– Randrade