這篇文章將為大家詳細講解有關JS如何實現兩周內自動登錄功能,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
具體內容如下
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>兩周內自動登錄</title> <script src="cookie.js" type="text/javascript" charset="utf-8"></script> </head> <body> <form action="" method="post" id="form1"> <input type="text" name="user" id="user" value="" /> <input type="password" name="pass" id="pass" value="" /> <input type="submit" value="提交" id="btn"/> <input type="checkbox" name="checkbox" id="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>
來自智能社的學習筆記延伸練習。
關于“JS如何實現兩周內自動登錄功能”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。