1.设置localStorage
Storage.set = function(name, val) {
localStorage.setItem(name, val);
}
2.获取localStorage
Storage.get = function(name) {
return localStorage.getItem(name);
}
3.调用函数
Storage.set("status", "OK");
Storage.set("quit", "...");
console.log(Storage.get("status"));
4.完整代码
<html>
<head>
<title>localStorage</title>
</head>
<body>
<script>
const Storage = {};
Storage.get = function(name) {
return localStorage.getItem(name);
}
Storage.set = function(name, val) {
localStorage.setItem(name, val);
}
Storage.set("status", "OK");
Storage.set("quit", "...");
console.log(Storage.get("status"));
</script>
</body>
</html>