Storage
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title>localStorage</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="mainbox">
<h2>localStorage</h2>
<button onclick="saveData()">点我保存一个数据</button>
<button onclick="readData()">点我读取一个数据</button>
<button onclick="deleteData()">点我删除一个数据</button>
<button onclick="clearData()">清空</button>
</div>
</body>
<!-- <script src="../js/vue.js"></script> -->
<script type="text/javascript">
let xx = {name:'key',value:'value值'}
function saveData() {
localStorage.setItem('key1','value数据1')
localStorage.setItem('key2','value数据2')
localStorage.setItem('key3',JSON.stringify(xx))
}
function readData() {
console.log(localStorage.getItem('key1'))
console.log(JSON.parse(localStorage.getItem('key3')))
}
function deleteData() {
localStorage.removeItem('key1')
}
function clearData() {
localStorage.clear()
}
</script>
</html>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title>sessionStorage</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="mainbox">
<h2>sessionStorage</h2>
<button onclick="saveData()">点我保存一个数据</button>
<button onclick="readData()">点我读取一个数据</button>
<button onclick="deleteData()">点我删除一个数据</button>
<button onclick="clearData()">清空</button>
</div>
</body>
<!-- <script src="../js/vue.js"></script> -->
<script type="text/javascript">
let xx = {name:'key',value:'value值'}
function saveData() {
sessionStorage.setItem('key1','value数据1')
sessionStorage.setItem('key2','value数据2')
sessionStorage.setItem('key3',JSON.stringify(xx))
}
function readData() {
console.log(sessionStorage.getItem('key1'))
console.log(JSON.parse(sessionStorage.getItem('key3')))
}
function deleteData() {
sessionStorage.removeItem('key1')
}
function clearData() {
sessionStorage.clear()
}
</script>
</html>