演示案例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
//增
var key = 'sex';
var value = 'man';
localStorage.setItem('nam', 'Mike');
localStorage.setItem(key, value);
localStorage.age = '18';
console.log(localStorage);
//查
console.log(localStorage.age);
console.log(localStorage.getItem('nam'));
console.log(localStorage.valueOf());
//改
localStorage.setItem('nam', 'Lucy');
//删
localStorage.removeItem('sex');
localStorage.clear();
</script>
</body>
</html>
标签:console,log,改查,nam,setItem,localstorage,key,增删,localStorage
From: https://blog.51cto.com/u_14476028/7323845