-
-
Save mkhuda/c182063f3278d48051a3 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> | |
<title>Percobaan HTML5 Local Storage</title> | |
<script type="text/javascript" charset="utf-8" src="jquery.js"></script> | |
<script type="text/javascript" > | |
// fungsi simpan(), ketika tombol diklik maka string | |
// di dalam input akan tersimpan ke dalam storage browser | |
function simpan() { | |
var storage = document.getElementById('nama').value; | |
localStorage.setItem('Text',storage); | |
} | |
// tampil() akan menampilkan string yang tersimpan | |
// ke tag div yang ditentukan "hasil" | |
function tampil() { | |
var tampilNama = localStorage.getItem('Text'); | |
if (tampilNama) { | |
x = document.getElementById('tampil'); | |
x.innerHTML=tampilNama; | |
} | |
} | |
// fungsi untuk menghapus localstorage browser | |
function hapus() { | |
localStorage.removeItem('Text'); | |
} | |
</script> | |
</head> | |
<body> | |
<input type="text" id="nama" /> | |
<input type="button" value="Simpan" onclick="simpan()" /> | |
<input type="button" value="Tampil" onclick="tampil()" /> | |
<input type="button" value="Hapus" onclick="hapus()" /> | |
<div id="tampil"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment