JS实现登录页面记住密码和enter键登录方法推荐
网络编程 2021-07-04 21:04www.168986.cn编程入门
狼蚁网站SEO优化长沙网络推广就为大家带来一篇JS实现登录页面记住密码和enter键登录方法推荐。长沙网络推广觉得挺不错的,现在分享给大家,也给大家做个参考。
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>按enter键触发事件和记住账号密码</title> <script> //方法一: // document.onkeypress=function(e){ // var keycode=document.all?event.keyCode:e.which; // if(keycode==13){ // alert_login(); // }; // } //方法二: document.onkeypress = viewKeyInfo; function viewKeyInfo(e) { var e = e || event; if ((e['keyCode'] == 13) || (e['which'] == 13)) { alert_login(); } } function body_onload(){ if (1 == get_saveauth_cookies()) { var tmp_user = ''; var tmp_pwd = ''; tmp_user = get_user_cookies(); tmp_pwd = get_pwd_cookies(); document.getElementById("tt_user").value = tmp_user; document.getElementById("pd_pwd").value = tmp_pwd; document.getElementById("chx_save_auth").checked = true; } } function alert_login(){ if (document.getElementById("chx_save_auth").checked == true) { var cookies_uesr = document.getElementById("tt_user").value; var cookies_pwd = document.getElementById("pd_pwd").value; setcookie('loginuser', cookies_uesr, 1440); setcookie('loginpwd', cookies_pwd, 1440); setcookie('saveauth', 1, 1440); } else { setcookie('saveauth', 0, 1440); } location = "https://.baidu."; } function setcookie(name,value,expirehours) { var cookieString=name+'='+escape(value); if (expirehours>0) { var date=new Date(); date.setTime(date.getTime()+expirehours*3600*1000); cookieString = cookieString + '; expires=' + date.toGMTString(); document.cookie = cookieString; } document.cookie=cookieString; } function getcookie(name) { var strCookie=document.cookie; var arrCookie=strCookie.split('; '); for (var i=0;i<arrCookie.length;i++) { var arr=arrCookie[i].split('='); if (arr[0]==name) return unescape(arr[1]); } return ''; } function get_user_cookies() { var tmp_val = getcookie('loginuser'); return tmp_val; } function get_pwd_cookies() { var tmp_val = getcookie('loginpwd'); return tmp_val; } function get_saveauth_cookies() { var tmp_val = getcookie('saveauth'); return tmp_val; } </script> </head> <body onload="body_onload()"> <p>user:<input type="text" id="tt_user" style="margin-left: 34px;width: 200px;"/></p> <p>password:<input type="password" id="pd_pwd" style="width: 200px;"/></p> <p><input type="checkbox" id="chx_save_auth"/>save password</p> <p><input type="button" onclick="alert_login()" value="login"/></p> <!--<input type="button" onclick="javascript:alert_login()" value="login"/> javascript:alert_login()与alert_login()无区别 --> </body> </html>
以上这篇JS实现登录页面记住密码和enter键登录方法推荐就是长沙网络推广分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持狼蚁SEO。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程