HTML本地存储

返回目录

作用方法
增 改 查localStorage.name
删除localStorage.removeItem(‘name’)
删除所有localStorage.clear()
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			localStorage.setItem('name','张三');//保存数据
			console.log(localStorage.getItem("name"));//读取数据
			localStorage.name2='ss';//保存数据
			localStorage['name3']='vv';//保存数据
			localStorage.obj={id:12,text:'22'}
			console.log(typeof localStorage.obj);
			console.log( localStorage.obj.id);
			console.log( localStorage.name2);
			// sessionStorage.age=10
			console.log(sessionStorage.age);
			// console.log(localStorage.age);
			console.log(localStorage.length);//获取保存的数据量
			console.log(localStorage.key(0));
			console.log(localStorage.removeItem('name'));//移除名为name的数据
			localStorage.clear()//移除所有数据
			
		</script>
	</body>
</html>

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 点我我会动 设计师:白松林 返回首页