lujiaxing
2023-07-27 13:39:40 +08:00
有没有听说过有一个东西叫 localstorage ?
```
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta name="Content-Type" content="text/html;charset=utf-8">
<title>Local Storage Test</title>
<script language="javascript" type="text/javascript">
function writeLocalStorage(text) {
localStorage.setItem("test", text);
}
function loadLocalStorage() {
return localStorage.getItem("test");
}
function save() {
var targetControl = document.getElementById("valueInput");
writeLocalStorage(targetControl.value);
}
function init() {
var targetControl = document.getElementById("valueInput");
var value = loadLocalStorage();
targetControl.value = value;
}
</script>
<style type="text/css">
.demo-area {
width: 640px;
height: 480px;
text-align: center;
position: absolute;
left: calc(50% - 320px);
top: calc(50% - 240px);
background-color: #0000FF11;
border-radius: 5px;
font-size: 14pt;
}
</style>
</head>
<body onload="init()">
<div class="demo-area">
<br /><br /><br /><br />
<br /><br /><br /><br />
<span>
<label for="valueInput">值: </label>
<input type="text" value="" id="valueInput" name="valueInput" />
</span>
<br /><br />
<button onclick="save()">保存</button>
</div>
</body>
</html>
```