Skip to content

Instantly share code, notes, and snippets.

@salimos
Created November 25, 2013 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salimos/7650874 to your computer and use it in GitHub Desktop.
Save salimos/7650874 to your computer and use it in GitHub Desktop.
Exemple LocalStorage
<html>
<head>
<title>afficher dans le LocalStorga</title>
<script type="text/javascript">
function show () {
document.write("<TABLE BORDER='5'><CAPTION> Meilleur score </CAPTION> <TR> <TH> Nom </TH> <TH> Score </TH> </TR> ")
for (var i=1; i<6; i++) {
document.write("<tr><td>")
document.write(localStorage.getItem("nom"+i),"</td><td>")
document.write(localStorage.getItem("score"+i),"</td></tr>")
}
document.write("</TABLE> ")
}
</script>
</head>
<body onload="show()">
</body>
</html>
<html>
<head>
<title>AJout dans le LocalStorga</title>
<script type="text/javascript">
function AjoutAutomatique () {
for (var i=1; i<6; i++) {
localStorage.setItem("nom"+i,"AAA")
localStorage.setItem("score"+i,"0")
}
}
function ajouterJoueur(nom, score) {
for( i = 1; i <= localStorage.length ; i++)
if( localStorage.getitem['score' + i] < score )
break;
for( c = i ; c <= localStorage.length; c++ ) {
localStorage.setitem("score" + ( C + 1), localStorage.getitem['score' + c] );
localStorage.setitem("nom" + ( C + 1), localStorage.getitem['nom' + c] );
}
localStorage.setitem("score"+i , score);
localStorage.setitem("nom"+i , nom);
}
</script>
</head>
<body onload="AjoutAutomatique()">
ajout OK
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment