您好,登錄后才能下訂單哦!
什么是localStorage
HTML5加入了localStorage,作為客戶本地存儲文件,之前用cookie,但是每條cookie空間為4K?localStorage?支持5M
一張圖了解下客戶端瀏覽器的存儲發(fā)展史
瀏覽器支持情況
Feature Chrome Firefox Internet Explorer Opera Safari Android Opera Mobile Safari Mobile
localStorage 4 3.5 8 10.50 4 2.1 11 iOS 3.2
sessionStorage 5 2 8 10.50 4 2.1 11 iOS 3.2
特點
判斷l(xiāng)ocalStorage
if(!window.localStorage){
alert("瀏覽器支持localstorage");
return false;
}else{
//開始浪
}
HTML5 localStorage 增刪改遍歷
var storage=window.localStorage;
storage.setItem("name","tom");
官方不太推薦,但是支持的寫法
storage["name"]="tom";
storage.name="tom";
var a1=storage.getItem("name");
官方不太推薦,但是支持的寫法
var a2=storage.name;
?
var a3=storage["name"];
更新?html5的localStorage 存的時候是單鍵值對 key-value模式,重新寫一遍name就是更新了
storage.setItem("name","Jack");
storage.removeItem("name");
var storage=window.localStorage;
storage.setItem("name1","tom");
storage.setItem("name2","jack");
storage.setItem("name3","Lucy");
?
for(var i=0;i<storage.length;i++){
var key = storage.key(i);
var value = storage.getItem(key);
console.log(key + " - " + value);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>測試localStorage</title>
</head>
?
<script>
if(!window.localStorage){
alert("瀏覽器不支持localstorage");
}else{
var storage=window.localStorage;
storage.setItem("a","tom");
console.log(typeof storage["a"]);
//第一種方法讀取
var a1=storage.getItem("a");
console.log(a1);
}
</script>
<body>
</body>
</html>
https://java-er.com/blog/html5-localstorage-all
MORE================
html5 localStorage緩存音樂和視頻
H5 localStorage 緩存圖片
H5 本地緩存localStorage緩存計數(shù)器
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經查實,將立刻刪除涉嫌侵權內容。