JS+HTML5本地存儲Localstorage實現(xiàn)注冊登錄及驗證功能示例
本文實例講述了JS+HTML5本地存儲Localstorage實現(xiàn)注冊登錄及驗證功能。分享給大家供大家參考,具體如下:
源碼引用的js、jquery都是在線的,代碼拷到本地就能運行
登錄:
<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 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="h1 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('密碼錯誤');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>
注冊:
<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 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="h1 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="ZhuCe()" 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 ZhuCe(){ if(NoKong()){ var arr = []; if(localStorage.user){ arr = eval(localStorage.user); for(e in arr){ if($('#loginName').val()==arr[e].loginName){ alert('該賬號已被注冊'); clear(); return; } } } var user = {'loginName':$("#loginName").val(),'loginPsd':$("#loginPsd").val()}; arr.push(user); localStorage.user=JSON.stringify(arr); 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>
更多關(guān)于JavaScript相關(guān)內(nèi)容還可查看本站專題:《JavaScript+HTML5特效與技巧匯總》、《JavaScript圖形繪制技巧總結(jié)》、《JavaScript錯誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運算用法總結(jié)》
希望本文所述對大家JavaScript程序設(shè)計有所幫助。
相關(guān)文章
理解 JavaScript Scoping & Hoisting(二)
這篇文章主要介紹了理解 JavaScript Scoping & Hoisting,盡管對于有經(jīng)驗的程序員來說這只是小菜一碟,不過我還是順著初學(xué)者常見的思路做一番描述2015-11-11JavaScript中的事件循環(huán)機制及其運行原理
JavaScript中的事件循環(huán)機制是一種異步處理機制,通過維護事件隊列和消息隊列,實現(xiàn)任務(wù)的分發(fā)和執(zhí)行。事件循環(huán)機制由主線程和任務(wù)隊列構(gòu)成,主線程運行完當前任務(wù)后會檢查任務(wù)隊列中是否有待執(zhí)行的任務(wù),如有則執(zhí)行,否則等待2023-04-04純js+css實現(xiàn)仿移動端淘寶網(wǎng)站的彈出詳情框功能
這篇文章主要介紹了純js+css實現(xiàn)仿移動端淘寶網(wǎng)站的彈出詳情框功能,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-12-12微信小程序搭建(mpvue+mpvue-weui+fly.js)的詳細步驟
這篇文章主要介紹了微信小程序搭建(mpvue+mpvue-weui+fly.js)的詳細步驟,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-09-09