您好,登錄后才能下訂單哦!
這篇文章主要介紹了JS+HTML5本地存儲Localstorage如何實現注冊登錄及驗證功能,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
源碼引用的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 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('密碼錯誤');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 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="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>
感謝你能夠認真閱讀完這篇文章,希望小編分享的“JS+HTML5本地存儲Localstorage如何實現注冊登錄及驗證功能”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業資訊頻道,更多相關知識等著你來學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。