久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      html5的web存儲(chǔ)

      以前我們?cè)诒镜卮鎯?chǔ)數(shù)據(jù)都是用document.cookie來存儲(chǔ)的,但是由于其的存儲(chǔ)大小只有4K左右,解析也很復(fù)雜,給開發(fā)帶來了諸多的不便.不過現(xiàn)在html5出了web的存儲(chǔ),彌補(bǔ)了cookie的不足,而且開放起來也是相當(dāng)?shù)姆奖?/span>

      web存儲(chǔ)分兩類

      sessionStorage

      容量大小約為5M左右,該方式的生命周期為關(guān)閉瀏覽器窗口為止

      localStorage

      容量大小約為20M左右, 存儲(chǔ)的數(shù)據(jù)不會(huì)隨著用戶瀏覽時(shí)會(huì)話過期而過期,但會(huì)應(yīng)用戶的請(qǐng)求而刪除。瀏覽器也因?yàn)榇鎯?chǔ)空間的限制或安全原因刪除它們.而且類型存儲(chǔ)的數(shù)據(jù)可以同一個(gè)瀏覽器的多個(gè)窗口共享

      注意點(diǎn):只能存儲(chǔ)字符串,如果是json對(duì)象的話,可以將對(duì)象JSON.stringify() 編碼后存儲(chǔ)

      方法詳解:

        setItem(key, value) 設(shè)置存儲(chǔ)內(nèi)容

        getItem(key) 讀取存儲(chǔ)內(nèi)容

        removeItem(key) 刪除鍵值為key的存儲(chǔ)內(nèi)容

        clear() 清空所有存儲(chǔ)內(nèi)容

      下面我們就給個(gè)給大家看一下他的寫法:

        //更新      function update() {          window.sessionStorage.setItem(key, value);      }    //獲取      function get() {          window.sessionStorage.getItem(key);      }    //刪除      function remove() {          window.sessionStorage.removeItem(key);      }    //清空所有數(shù)據(jù)      function clear() {          window.sessionStorage.clear();      }

      查看效果的話,我們以谷歌瀏覽器為例子:

      html5的web存儲(chǔ)

      以前的老版本的話,是沒有Application的,老版本的為Resource

      存儲(chǔ)完數(shù)據(jù)后的

      html5的web存儲(chǔ)

      下面我就給大家展示記錄用戶名和密碼的經(jīng)典例子

      html5的web存儲(chǔ)

      當(dāng)記住密碼的復(fù)選框勾上的時(shí)候,下次打開的時(shí)候,用戶名和密碼就不需要在重新輸入了

      html部分:

      <label for="">
      用戶名: <input type="text" class="userName"/>
      </label>
      <br/><br/>
      <label for="">
      密 碼: <input type="password" class="pwd"/>
      </label>
      <br/><br/>
      <label for="">
      <input type="checkbox" class="ckb"/>
      記住密碼
      </label>
      <br/><br/>
      <button>登錄</button>

      js部分

        var userName=document.querySelector('.userName');    var pwd=document.querySelector('.pwd');    var sub=document.querySelector('button');    var ckb=document.querySelector('.ckb');        sub.onclick=function(){//        如果記住密碼 被選中存儲(chǔ),用戶信息          if(ckb.checked){              window.localStorage.setItem('userName',userName.value);              window.localStorage.setItem('pwd',pwd.value);          }else{              window.localStorage.removeItem('userName');              window.localStorage.removeItem('pwd');          }//        否則清除用戶信息    }        window.onload=function(){//        當(dāng)頁(yè)面加載完成后,獲取用戶名,密碼,填充表單          userName.value=window.localStorage.getItem('userName');          pwd.value=window.localStorage.getItem('pwd');      }

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)