您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要介绍了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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。