-2
I wanted to have the amount of clicks stored in the Torage locale, and when I returned the number of clicks continued where it left off. I tried to do so, but no alert
only shows NaN
:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>
</head>
<body>
<script type="text/javascript">
var p = document.createElement("p");
document.body.appendChild(p);
$(document).ready(function(){
var cout = localStorage.getItem('cout') || 0;
$("#btnCount").click(function(){
cout = parseInt(cout)+1;
$('p').html(cout);
alert(cout);
localStorage.setItem('cout',cout);
});
});
</script>
<button type="button" id="btnCount">Click me</button>
</body>
</html>
This is an answer to your question or more information that should belong to the question ?
– Isac