因为论坛有一些开发者, 把html的记住密码代码分享给大家,以便大家一起学习。
<!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title></title> </head> <body> 账号:<input type="text" id="user"> 密码: <input type="password" id="pwd"> 记住密码: <input type="checkbox" id="remember"> <button onclick="fn()">登录</button> <script type="text/javascript"> var user = document.getElementById('user'), pass = document.getElementById('pwd'), check = document.getElementById('remember'), localUser = localStorage.getItem('user') || ''; //获取到user的值并保存 localPass = localStorage.getItem('pass') || ''; //获取到pwd的值并保存 user.value = localUser; pass.value = localPass; if (localUser !== '' && localPass !== '') { check.setAttribute('checked', ''); } function fn() { if (check.checked) { localStorage.setItem('user', user.value); localStorage.setItem('pass', pass.value); } else { localStorage.setItem('user', ''); localStorage.setItem('pass', ''); } } </script> </body> </html>相关帖子:小米运动微信步数提交平台源码-网络技能-小轻论坛
湖北,武汉,汉阳区