您好,登錄后才能下訂單哦!
這篇文章主要介紹了JS+HTML5本地存儲(chǔ)Localstorage如何實(shí)現(xiàn)注冊(cè)登錄及驗(yàn)證功能,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
源碼引用的js、jquery都是在線的,代碼拷到本地就能運(yùn)行
登錄:
<html ng-app="ionicApp"> <head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> <title>登錄</title> <link href="https://cdn.bootcss.com/ionic/1.3.2/css/ionic.css" rel="external nofollow" rel="external nofollow" rel="stylesheet"> <script src="https://cdn.bootcss.com/ionic/1.3.2/js/ionic.bundle.min.js"></script> </head> <body> <div class="bar bar-header"> <div class="h2 title">登錄</div> </div> <div class="content has-header"> <div class="list"> <label class="item item-input"> <span class="input-label">用戶名:</span> <input id="loginName" type="text"> </label> <label class="item item-input"> <span class="input-label">密碼:</span> <input id="loginPsd" type="password"> </label> </div> <div class="padding"> <button οnclick="login()" class="button button-block button-positive">登錄</button> </div> </div> <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script> <script>function login(){if(NoKong()){if(localStorage.user){arr = eval(localStorage.user);//獲取localStoragevar k = 0;for(e in arr){if($('#loginName').val()==arr[e].loginName){if($('#loginPsd').val()==arr[e].loginPsd){alert('登錄成功');clear();k = 0;return;}else{alert('密碼錯(cuò)誤');clear();k = 0;return;}}else{ k = 1;}}if(k==1){alert('用戶名不存在');clear();}}else{alert('用戶名不存在');clear();}}}function clear(){$('#loginName').val('');$("#loginPsd").val('');}function NoKong(){if($('#loginName').val()==""){alert('用戶名不能為空');return false;}else if($('#loginPsd').val()==""){alert('密碼不能為空');return false;}return true;}</script> </body></html>
注冊(cè):
<html ng-app="ionicApp"> <head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> <title>注冊(cè)</title> <link href="https://cdn.bootcss.com/ionic/1.3.2/css/ionic.css" rel="external nofollow" rel="external nofollow" rel="stylesheet"> <script src="https://cdn.bootcss.com/ionic/1.3.2/js/ionic.bundle.min.js"></script> </head> <body> <div class="bar bar-header"> <div class="h2 title">注冊(cè)</div> </div> <div class="content has-header"> <div class="list"> <label class="item item-input"> <span class="input-label">用戶名:</span> <input id="loginName" type="text"> </label> <label class="item item-input"> <span class="input-label">密碼:</span> <input id="loginPsd" type="password"> </label> </div> <div class="padding"> <button οnclick="ZhuCe()" class="button button-block button-positive">注冊(cè)</button> </div> </div> <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script> <script> function ZhuCe(){ if(NoKong()){ var arr = []; if(localStorage.user){ arr = eval(localStorage.user); for(e in arr){ if($('#loginName').val()==arr[e].loginName){ alert('該賬號(hào)已被注冊(cè)'); clear(); return; } } } var user = {'loginName':$("#loginName").val(),'loginPsd':$("#loginPsd").val()}; arr.push(user); localStorage.user=JSON.stringify(arr); alert('注冊(cè)成功'); clear(); } } function clear(){ $('#loginName').val(''); $("#loginPsd").val(''); } function NoKong(){ if($('#loginName').val()==""){ alert('用戶名不能為空'); return false; }else if($('#loginPsd').val()==""){ alert('密碼不能為空'); return false; } return true; } </script> </body> </html>
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“JS+HTML5本地存儲(chǔ)Localstorage如何實(shí)現(xiàn)注冊(cè)登錄及驗(yàn)證功能”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來(lái)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。