Created
November 25, 2013 23:39
-
-
Save salimos/7650874 to your computer and use it in GitHub Desktop.
Exemple LocalStorage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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