佳木斯湛栽影视文化发展公司

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

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

熱門標(biāo)簽:使用U盤裝系統(tǒng) 阿里云 硅谷的囚徒呼叫中心 檢查注冊(cè)表項(xiàng) 百度競(jìng)價(jià)點(diǎn)擊價(jià)格的計(jì)算公式 美圖手機(jī) 智能手機(jī) 網(wǎng)站建設(shè)

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

  • localStorage - 沒有時(shí)間限制的數(shù)據(jù)存儲(chǔ)
  • sessionStorage - 針對(duì)一個(gè) session 的數(shù)據(jù)存儲(chǔ)

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

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

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

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

localStorage 方法存儲(chǔ)的數(shù)據(jù)沒有時(shí)間限制。第二天、第二周或下一年之后,數(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>

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

標(biāo)簽:黃山 山南 賀州 通遼 湖北 懷化 湘潭 煙臺(tái)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《html5超簡(jiǎn)單的localStorage實(shí)現(xiàn)記住密碼的功能實(shí)現(xiàn)》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    寻甸| 永城市| 大埔县| 嘉义县| 绥江县| 长沙市| 宁强县| 丰镇市| 广昌县| 十堰市| 邵阳县| 尼木县| 丁青县| 北宁市| 东平县| 鹤壁市| 台安县| 察哈| 望城县| 泰来县| 红河县| 屏东市| 泽州县| 万宁市| 靖边县| 客服| 南安市| 济南市| 保德县| 景洪市| 阳谷县| 伊宁市| 项城市| 唐山市| 治县。| 宁晋县| 七台河市| 鄂托克旗| 多伦县| 花莲县| 灌云县|