首页 > 代码库 > sessionStorage

sessionStorage

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
sessionStorage.setItem(‘上单‘,‘盖轮‘);
sessionStorage.setItem(‘中弹‘,‘金克斯‘);
sessionStorage.setItem(‘下蛋‘,‘提莫‘);
var sg=sessionStorage.getItem(‘上单‘);
console.log(sg); //盖轮
var sk=sessionStorage.key(0);
console.log(sk); //上单
for(var i=0;i<sessionStorage.length;i++){
var key=sessionStorage.key(i);
console.log(sessionStorage.getItem(key)); // 盖轮 提莫 金克斯
}
sessionStorage.removeItem(‘下蛋‘);
sessionStorage.clear();
localStorage.setItem(‘上单‘,‘gay轮‘);
localStorage.setItem(‘中弹‘,‘萝莉‘);
localStorage.setItem(‘下蛋‘,‘蘑菇精‘);

var obj={
seti:function(a,b){
localStorage.setItem(a,b)
},
geti:function(c){
return localStorage.getItem(c)
},
rem:function(d){
localStorage.removeItem(d)
},
cle:function(){
localStorage.clear();
}
};

obj.seti(‘金克斯‘,‘拉克丝‘);
console.log(obj.geti(‘下蛋‘)); //蘑菇精
obj.rem(‘上单‘);
obj.cle();
</script>
</body>
</html>

sessionStorage