3
I want to create a simple element-based pagination within an array.
When arriving at the first and/or last element of the array, I would like to disable the respective navigation button (e.g., by changing from disabled=false
for disabled=true
)
Code
<button onclick="Anterior();" id="menos">Anterior</button>
<span id='numero'> </span>
<button onclick="Proximo();" id="mais">Próximo</button>
<script>
var elemento = new Array(1, 2, 3, 2, 7);
contar = 0
Proximo = function() {
contar ++;
...
};
Anterior = function() {
contar --;
...
};
// retorna o primeiro indice do array
var menor = document.write(elemento.indexOf(searchElement[, fromIndex]))
// retorna o último índice do array
var maior = document.write(elemento.slice(-1)[0])
if (contar == menor) {
document.getElementById('menos').disabled=true;
}
if (contar == maior) {
document.getElementById('mais').disabled=true;
}
</script>
Then I would look aesthetically like this:
[ Previous ] - 3 - [ Next ]
I’d like him to count inside the element span
Thanks Miguelito, funfou legal!
– Diego Henrique