欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

使用JS獲取SessionStorage的值

獲取sessionStorage的意義

成都創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供東山網(wǎng)站建設(shè)、東山做網(wǎng)站、東山網(wǎng)站設(shè)計(jì)、東山網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、東山企業(yè)網(wǎng)站模板建站服務(wù),10年東山做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。

首先獲取它是為了將獲得的信息輸出或者alert();讓人容易看到,

其次,在靜態(tài)頁面中,如果使用sessionStorage就相當(dāng)于在動(dòng)態(tài)頁面里連接了數(shù)據(jù)庫一樣

例如:我上一篇所做的為button按鈕添加回車事件的項(xiàng)目中所用到的可以使用js中的sessionStorage獲取頁面輸入的信息,也可以獲得后臺(tái)計(jì)算所得的數(shù)據(jù),并且顯示出來。

廢話不多說,看代碼重要:

具體實(shí)現(xiàn)

<script type="text/javascript">
    function login(){
      var username=window.document.getElementById("username").value;
      var password=window.document.getElementById("password").value;
      if(password=="123456")
      {
        window.sessionStorage.setItem("username", username);
        window.location.href="../index1.html" rel="external nofollow" ;
      }else{
        alert("密碼錯(cuò)誤請(qǐng)輸入正確的密碼,例如:123456!");
        return false;
      }
    }
</script>
<input type="text" id="username" class="11" placeholder="請(qǐng)輸入真實(shí)姓名"/>
<input type="password" id="password" placeholder="請(qǐng)輸入密碼(默認(rèn)密碼123456)"/>
<input type="button" value="登錄考試" onclick="login()">

以上代碼是獲取username的值并傳到下一個(gè)界面

并且獲得password的值與事先設(shè)置好的對(duì)比,不同就是錯(cuò)誤 就不可以登錄

<script>
   $(function () {
     var username= window.sessionStorage.getItem("username")
     $("#yhm").html("登錄用戶:"+username)
     $("#name").html(username)
     if(window.sessionStorage.getItem("username")===null){
       alert("您還沒有登錄,請(qǐng)登錄后重試!")
       window.location.href="Pages/index.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" ;
     }
     $("#esc").on("click",function(){
       window.sessionStorage.clear();
       window.location.href="Pages/index.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" ;
     });
  })
 </script>

獲取前段頁面輸入的值并且顯示至對(duì)應(yīng)的位置

<div id="yhm"></div> 

并且判斷是否有sessionStorage的值,如果沒有,自動(dòng)返回登錄頁面,并做出相應(yīng)的提示

點(diǎn)擊事件觸發(fā)后清空sessionStorage的值

<script>
$("#esc").on("click",function(){
       window.sessionStorage.clear();
       window.location.href="Pages/index.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" ;
     });
</script>

當(dāng)點(diǎn)擊id為esc的按鈕時(shí)觸發(fā)clear事件

<button id="esc" >退出考試系統(tǒng)</button> 

則自動(dòng)返回登錄界面

總結(jié)

以上所述是小編給大家介紹的使用JS獲取SessionStorage的值,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)創(chuàng)新互聯(lián)網(wǎng)站的支持!

分享標(biāo)題:使用JS獲取SessionStorage的值
文章起源:http://www.chinadenli.net/article20/ishjco.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)網(wǎng)站導(dǎo)航做網(wǎng)站全網(wǎng)營銷推廣用戶體驗(yàn)Google

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)