<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        HTML5本地存儲應用sessionStorage和localStorage

        來源:懂視網(wǎng) 責編:小采 時間:2020-11-27 15:07:26
        文檔

        HTML5本地存儲應用sessionStorage和localStorage

        HTML5本地存儲應用sessionStorage和localStorage:在html5之前,瀏覽器要實現(xiàn)數(shù)據(jù)的存儲,一般都是用cookie,但是cookie有域名和大小限定. html5流行之后,可以通過localStorage和sessionStorage實現(xiàn)瀏覽器端的數(shù)據(jù)存儲,這兩者有什么特點呢?sessionStorage sessionStorage屬于臨時會
        推薦度:
        導讀HTML5本地存儲應用sessionStorage和localStorage:在html5之前,瀏覽器要實現(xiàn)數(shù)據(jù)的存儲,一般都是用cookie,但是cookie有域名和大小限定. html5流行之后,可以通過localStorage和sessionStorage實現(xiàn)瀏覽器端的數(shù)據(jù)存儲,這兩者有什么特點呢?sessionStorage sessionStorage屬于臨時會

        在html5之前,瀏覽器要實現(xiàn)數(shù)據(jù)的存儲,一般都是用cookie,但是cookie有域名和大小限定.

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

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

        localStorage

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

      2. 存儲量限制 ( 5M )

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

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

      5. 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>
        <p>
         用戶名: <input type="text"/>
        </p>
        
        <p>
         性別: <br/>
         <input type="radio" name="sex" value="男"/>男
         <input type="radio" name="sex" value="女"/>女
        </p>
        
        <p>
         備注:
         <textarea cols="30" rows="10"></textarea>
        </p>
        
        </body>
        </html>

        聲明:本網(wǎng)頁內容旨在傳播知識,若有侵權等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        HTML5本地存儲應用sessionStorage和localStorage

        HTML5本地存儲應用sessionStorage和localStorage:在html5之前,瀏覽器要實現(xiàn)數(shù)據(jù)的存儲,一般都是用cookie,但是cookie有域名和大小限定. html5流行之后,可以通過localStorage和sessionStorage實現(xiàn)瀏覽器端的數(shù)據(jù)存儲,這兩者有什么特點呢?sessionStorage sessionStorage屬于臨時會
        推薦度:
        標簽: 應用 存儲 html5
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 亚洲国产精品网站久久| 亚洲精品无码专区久久同性男| 亚洲av永久无码精品古装片| 麻豆va在线精品免费播放| 国产91在线免费| 国产亚洲精品免费| 亚洲国产精品综合久久一线| 麻豆69堂免费视频| 久久精品国产精品亚洲| 国产免费牲交视频免费播放| 国产亚洲成AV人片在线观黄桃| 国产一级片免费看| 亚洲理论片在线中文字幕| 成人免费午间影院在线观看| 男人的天堂av亚洲一区2区| 免费一级毛片不卡在线播放| 一级做性色a爰片久久毛片免费| 亚洲精品午夜无码电影网| 国产好大好硬好爽免费不卡| 亚洲无限乱码一二三四区| 韩国免费三片在线视频| 日亚毛片免费乱码不卡一区| 亚洲韩国精品无码一区二区三区| 久久精品国产影库免费看| 亚洲另类自拍丝袜第1页| 国产精品高清全国免费观看| 9久热这里只有精品免费| 亚洲精品亚洲人成在线麻豆| 小小影视日本动漫观看免费 | 亚洲va乱码一区二区三区| 免费黄色大片网站| 99精品全国免费观看视频..| 亚洲午夜免费视频| 国产一级高清免费观看| 久久久久久成人毛片免费看| 亚洲色大成WWW亚洲女子| 亚洲国产一二三精品无码| 搡女人免费视频大全| 一级有奶水毛片免费看| 亚洲国产精品一区二区三区在线观看| 日韩精品电影一区亚洲|