localStorage与sessionStorage的增删改查

2020-10-30 11:06:45 浏览数 (1)

代码语言:javascript复制
<!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 type="text/javascript">
		
		//增
		localStorage['李文']="美女";
		//查询
		alert(localStorage.李文);
		localStorage.clear();//清空所有的localStorage.null
		//获取
		alert(localStorage.getItem("李文"));
		//存储
		localStorage.setItem("陈业贵",666);
		localStorage.setItem("李文",999);
		//修改
		localStorage["陈业贵"]=999;
		//删除
		localStorage.removeItem("李文");
		//查询
		console.log(localStorage);
	</script>
</body>
</html>
代码语言:javascript复制
<!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 type="text/javascript">
			
		//新增
		sessionStorage.b=666;
		console.log(sessionStorage)
	</script>
</body>
</html>
代码语言:javascript复制
<!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 type="text/javascript">
	
console.error('郭然要倒霉了');//错误
	alert(1);
	console.warn('高波今天高兴了')//警告




</script>
 </body>
 </html> 

0 人点赞