国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > HTML > 正文

HTML5本地存儲應用sessionStorage和localStorage

2020-03-24 16:00:41
字體:
來源:轉載
供稿:網友
html5之前,瀏覽器要實現(xiàn)數(shù)據(jù)的存儲,一般都是用cookie,但是cookie有域名和大小限定.

html5流行之后,可以通過localStorage和sessionStorage實現(xiàn)瀏覽器端的數(shù)據(jù)存儲,這兩者有什么特點呢?

sessionStorage
sessionStorage屬于臨時會話,數(shù)據(jù)存儲的有效期為:從頁面打開到頁面關閉的時間段,屬于窗口的臨時存儲,頁面關閉,本地存儲消失

localStorage

永久存儲(可以手動刪除數(shù)據(jù))

存儲量限制 ( 5M )

客戶端完成,不會請求服務器處理

sessionStorage數(shù)據(jù)在頁面之間不能共享、 而localStorage可以實現(xiàn)頁面之間共享

sessionStorage的應用:

 !DOCTYPE html  html  head  meta charset= UTF-8  title /title  script  window.onload = function(){ var aInput = document.getElementsByTagName( input  aInput[0].onclick = function(){ //sessionStorage: 臨時存儲, 只在當前頁面有效,不能傳遞到其他頁面,頁面關閉之后消失 window.sessionStorage.setItem( name , aInput[3].value ); aInput[1].onclick = function(){ alert(window.sessionStorage.getItem( name )); aInput[2].onclick = function(){ window.sessionStorage.removeItem( name ); /script  /head  body  input type= button value= 設置 /  input type= button value= 獲取 /  input type= button value= 刪除 /  br/  input type= text /  /body  /html 


localStorage的應用

 !DOCTYPE html  html  head  meta charset= UTF-8  title /title  script  window.onload = function(){ var aInput = document.getElementsByTagName( input  aInput[0].onclick = function(){ //localStorage : 永久性存儲 window.localStorage.setItem( name , aInput[3].value); window.localStorage.setItem( name2 , aaaaa  aInput[1].onclick = function(){ alert( window.localStorage.getItem( name ) ); alert( window.localStorage.getItem( name2 ) ); aInput[2].onclick = function(){ window.localStorage.removeItem( name // window.localStorage.clear(); /script  /head  body  input type= button value= 設置 /  input type= button value= 獲取 /  input type= button value= 刪除 /  br/  input type= text /  /body  /html 
 !DOCTYPE html  html  head  meta charset= UTF-8  title /title  script  window.onload = function () { var aInput = document.getElementsByTagName( input  var oT = document.querySelector( textarea  if (window.localStorage.getItem( userName )) { aInput[0].value = window.localStorage.getItem( userName  for (var i = 0; i aInput.length; i++) { if (window.localStorage.getItem( sex ) == aInput[i].value) { aInput[i].checked = true; if (window.localStorage.getItem( note )) { oT.value = window.localStorage.getItem( note  window.onunload = function () { if (aInput[0].value) { window.localStorage.setItem( userName , aInput[0].value); for (var i = 0; i aInput.length; i++) { if (aInput[i].checked == true) { window.localStorage.setItem( sex , aInput[i].value); if (oT.value) { window.localStorage.setItem( note , oT.value); /script  /head  body  用戶名: input type= text /  性別: br/  input type= radio name= sex value= 男 / 男 input type= radio name= sex value= 女 / 女 textarea cols= 30 rows= 10 /textarea  /body  /html 

以上就是HTML5本地存儲應用sessionStorage和localStorage的詳細內容,其它編程語言

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 龙门县| 镇巴县| 湘阴县| 阳西县| 通渭县| 汨罗市| 岐山县| 陆丰市| 扶余县| 万州区| 新乡县| 平乐县| 剑阁县| 奉节县| 武义县| 贵州省| 安仁县| 濮阳市| 乐东| 红原县| 修武县| 阿巴嘎旗| 丁青县| 芦溪县| 区。| 高青县| 巫溪县| 万盛区| 陕西省| 南丹县| 格尔木市| 绥阳县| 额济纳旗| 乐亭县| 金塔县| 乳山市| 宣武区| 曲沃县| 五华县| 沙洋县| 松潘县|