網頁存儲web storage---購物車(會員登錄)

網頁存儲web storage:實現購物車操作的會員登錄部分

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>shopping car</title>
    <script type="text/javascript">
function sendok(){
    if(userid.value!="" && userpwd.value!=""){
        localStorage.userid=userid.value;
        sessionStorage.userpwd=userpwd.value;
        return true;
    }else{
        alert("請輸入賬號");
        return false;
    }
}

function isload(){
    if(localStorage.userid){
        userid.value=localStorage.userid;
    }



}
    </script>
</head>
<body onload="isload();">
    <form action="ch05_05.htm" method="post" onsubmit="return sendok();">
        <div>
            <label for="userName">請輸入你的賬號</label>
            <input type="text" id="userid" name="" id="" value="" autofocus/>
        </div>
        <div>
            <label for="userName">請輸入你的密碼</label>
            <input type="password" id="userpwd" name="" id="" value="" autofocus/>
        </div>      
        <input id="btn_send" type="submit" value="登錄"/>
    </form>
</body>
</html>

說明:
(1)用戶關閉網頁,信息繼續保留,使用localStorage;
用戶關閉網頁,信息銷燬,使用sessionStorage;
(2)因此,用戶名使用localStorage,密碼使用sessionStorage;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章