濮阳杆衣贸易有限公司

主頁 > 知識庫 > html5超簡單的localStorage實(shí)現(xiàn)記住密碼的功能實(shí)現(xiàn)

html5超簡單的localStorage實(shí)現(xiàn)記住密碼的功能實(shí)現(xiàn)

熱門標(biāo)簽:黃島區(qū)地圖標(biāo)注 當(dāng)涂高德地圖標(biāo)注 江蘇智能電銷機(jī)器人哪家好 四川點(diǎn)撥外呼系統(tǒng) 南寧點(diǎn)撥外呼系統(tǒng)哪家公司做的好 云南大理400電話申請官方 電銷機(jī)器人電話用什么卡 成都智能外呼系統(tǒng)平臺 鎮(zhèn)江智能外呼系統(tǒng)有效果嗎

HTML5 提供了兩種在客戶端存儲數(shù)據(jù)的新方法:

  • localStorage - 沒有時間限制的數(shù)據(jù)存儲
  • sessionStorage - 針對一個 session 的數(shù)據(jù)存儲

之前,這些都是由 cookie 完成的。但是 cookie 不適合大量數(shù)據(jù)的存儲,因?yàn)樗鼈冇擅總€對服務(wù)器的請求來傳遞,這使得 cookie 速度很慢而且效率也不高。

在 HTML5 中,數(shù)據(jù)不是由每個服務(wù)器請求傳遞的,而是只有在請求時使用數(shù)據(jù)。它使在不影響網(wǎng)站性能的情況下存儲大量數(shù)據(jù)成為可能。

對于不同的網(wǎng)站,數(shù)據(jù)存儲于不同的區(qū)域,并且一個網(wǎng)站只能訪問其自身的數(shù)據(jù)。

HTML5 使用 JavaScript 來存儲和訪問數(shù)據(jù)。

localStorage 方法存儲的數(shù)據(jù)沒有時間限制。第二天、第二周或下一年之后,數(shù)據(jù)依然可用。

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8">
    <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
</head>
<style type="text/css">
    form{
        width: 300px;
        padding: 10px 0px 20px 30px;
        height:auto;
        border-radius: 6px;
        border-left:8px solid #19a049;
        background:#eee;
        margin:100px auto;
    }
    #user,#pass{
        padding: 8px;
        outline: none;
        background: transparent;
        border:1px solid #999;
        margin-top: 5px;
    }
    #sub{
        padding: 6px;
        outline: none;
        border:none;
        background: #19a049;
        color:#fff;
        width: 150px;
        border-radius: 6px;
        cursor: pointer;
    }
</style>
<body>
    <form action="" method="" onsubmit="return loginBtn_click();">
        <h3>Log in</h3>
        <input type="text" name="user" placeholder="user" id="user">
        <input type="password" name="pass" placeholder="password" id="pass">
        <input type="checkbox" id="remember" checked><br/><br/>
        <input type="submit" id="sub">
    </form>
</body>
<script type="text/javascript">
    $(document).ready(function(){

        var strName = localStorage.getItem('keyName');
        var strPass = localStorage.getItem('keyPass');
        if(strName){
            $('#user').val(strName);
        }if(strPass){
            $('#pass').val(strPass);
        }

    });

    function loginBtn_click(){
            var strName = $('#user').val();
            var strPass = $('#pass').val();
            localStorage.setItem('keyName',strName);
            if($('#remember').is(':checked')){
                localStorage.setItem('keyPass',strPass);
            }else{
                localStorage.removeItem('keyPass');
            }
        }
</script>
</html>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

標(biāo)簽:淮安 酒泉 十堰 廣西 佳木斯 咸寧 西寧 南京

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《html5超簡單的localStorage實(shí)現(xiàn)記住密碼的功能實(shí)現(xiàn)》,本文關(guān)鍵詞  html5,超,簡單,的,localStorage,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《html5超簡單的localStorage實(shí)現(xiàn)記住密碼的功能實(shí)現(xiàn)》相關(guān)的同類信息!
  • 本頁收集關(guān)于html5超簡單的localStorage實(shí)現(xiàn)記住密碼的功能實(shí)現(xiàn)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    天峨县| 德钦县| 玉树县| 公主岭市| 天津市| 阿巴嘎旗| 江城| 天门市| 内江市| 东宁县| 赫章县| 潜山县| 黑山县| 文登市| 星座| 宝应县| 九龙坡区| 紫云| 泰兴市| 梓潼县| 阿克陶县| 安庆市| 阳朔县| 渑池县| 分宜县| 邵武市| 亳州市| 陆丰市| 商丘市| 南京市| 和林格尔县| 偃师市| 新龙县| 宁陵县| 大荔县| 资溪县| 龙井市| 双流县| 子长县| 扎赉特旗| 青岛市|