JS實現(xiàn)登錄頁面記住密碼和enter鍵登錄方法推薦
更新時間:2016年05月10日 14:56:54 投稿:jingxian
下面小編就為大家?guī)硪黄狫S實現(xiàn)登錄頁面記住密碼和enter鍵登錄方法推薦。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>按enter鍵觸發(fā)事件和記住賬號密碼</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://www.baidu.com"; } 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()無區(qū)別 --> </body> </html>
以上這篇JS實現(xiàn)登錄頁面記住密碼和enter鍵登錄方法推薦就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
javascript使用正則實現(xiàn)去掉字符串前面的所有0
這篇文章主要介紹了javascript使用正則實現(xiàn)去掉字符串前面的所有0,需要的朋友可以參考下2018-07-07原生javaScript做得動態(tài)表格(注釋寫的很清楚)
因為看公司好多用動態(tài)表格的,所以,我就試著用js做了動態(tài)表格,下面有個不錯的示例,感興趣的朋友可以參考下2013-12-12Three.js利用性能插件stats實現(xiàn)性能監(jiān)聽的方法
Three.js 是一款運行在瀏覽器中的 3D 引擎,你可以用它創(chuàng)建各種三維場景,而下面這篇文章主要給大家介紹了關(guān)于Three.js如何利用性能插件stats實現(xiàn)性能監(jiān)聽的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起學習學習吧。2017-09-09