0
So, I was testing here my code to make an android app for balance, I am using Ionic, but when I test the code it does not work in Ionic, but only in the browser and in normal test (like only index.html), Ionic does not work
Obs: I think javascript is loading before DOM because what is inside functions works
javascript:
<script>
document.getElementById("saldo").innerHTML = parseInt(localStorage.getItem("saldo"))
function ir(){
const input = document.getElementById("valor").value
const saldo = localStorage.saldo ? localStorage.saldo : localStorage.setItem("saldo", 0)
if(!input){
return alert("Faltou preencher algo")
}
var resolucão = parseInt(saldo ? saldo : 0) + parseInt(input)
localStorage.setItem("saldo", parseInt(resolucão))
document.getElementById('saldo').innerHTML = resolucão
}
function resetar(){
localStorage.setItem("saldo", 0)
alert('Saldo resetado')
document.getElementById("saldo").innerHTML = 0
}
</script>
html:
<ion-content>
<div class="ion-padding">
<h1 id="h2">Seu saldo:</h1>
<h2 id="saldo">0</h2>
<h3>Quanto?</h3>
<input type="text" id="valor"/>
<h5>Pronto, agora para terminar, é so clicar em ir</h5>
<button id="butao" onclick="ir()">Ir</button>
<button onclick="resetar()">Resetar</button>
</div>
</ion-content>
thanks in advance
That tag
<script>
is inside the HTML file?– Woss
@Andersoncarloswoss not, it stays in another file
– Ronkzinho
@Andersoncarloswoss knows what to do?
– Ronkzinho