JS实现两周内自动登录功能

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>两周内自动登录</title> <script src="https://www.jb51.net/cookie.js" type="text/javascript" charset="utf-8"></script> </head> <body> <form action="" method="post"> <input type="text" value="" /> <input type="password" value="" /> <input type="submit" value="提交"/> <input type="checkbox" value="" />两周内自动登录 </form> </body> <script type="text/javascript"> var oTxt1 = document.getElementsByName('user')[0], oTxt2 = document.getElementsByName('pass')[0], cked = document.getElementsByName('checkbox')[0], oForm1 = document.getElementById('form1'), oBtn = document.getElementById('btn'); oForm1.onsubmit = function(){ if(cked.checked){ alert('请注意!您已勾选自动登录。为了保护您的账号安全,请不要在公共电脑上这样做。') setCookie('user',oTxt1.value,14); setCookie('pass',oTxt2.value,14); } } oTxt1.value = getCookie('user'); oTxt2.value = getCookie('pass'); </script> </html>

来自智能社的学习笔记延伸练习。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwypxz.html