Javascript實(shí)現(xiàn)登錄記住用戶名和密碼功能
話不多說(shuō),請(qǐng)看代碼:
<script type="text/javascript"> $(document).ready(function () { $("#UserAccount").focus(); //記住用戶名和密碼 $('#remebers').click(function () { if ($("#UserAccount").val() == "") { alert("用戶名不能為空!"); } if($("#UserPassword").val() == "") { alert("密碼不能為空!"); } else { if ($('#remebers').attr("checked")) { setCookie("uname", $("#UserAccount").val(), 60); setCookie("upwd", $("#UserPassword").val(), 60); } else { delCookie("uname"); delCookie("upwd"); } } }); if (getCookie("uname") != null) { $('#remebers').attr("checked", "checked"); $('#UserAccount').val(getCookie("uname")); $('#UserPassword').val(getCookie("upwd")); } }) //寫(xiě)cookies function setCookie(name, value) { var Days = 30; var exp = new Date(); exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000); document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString(); } //讀取cookies function getCookie(name) { var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); if (arr = document.cookie.match(reg)) return unescape(arr[2]); else return null; } //刪除cookies function delCookie(name) { var exp = new Date(); exp.setTime(exp.getTime() - 1); var cval = getCookie(name); if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString(); } </script> <div class="main"> <section id="login_form"> @using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post)) { @Html.AntiForgeryToken() @Html.ValidationSummary(true) <table> <tr> <td align="right">賬 號(hào):</td> <td align="left"><input type="text" id="UserAccount" name="UserAccount" /> @Html.ValidationMessageFor(m => m.UserAccount)</td> </tr> <tr> <td align="right">密 碼:</td> <td align="left"> <input type="password" id="UserPassword" name="UserPassword" /> @Html.ValidationMessageFor(m => m.UserPassword) </td> </tr> <tr> <td></td> <td align="left"> <input name="remebers" id="remebers" type="checkbox" /> <span style="color:#4a4949">記住用戶名和密碼</span> </td> </tr> <tr> <td></td> <td align="left"> <input type="submit" name="submit" id="submit" value="" style=" background: url(../../Images/Login/login_submit.jpg) no-repeat; height: 25px; width: 59px; " /> <input type="reset" name="reset" id="reset" value="" style="background: url(../../Images/Login/login_reset.jpg) no-repeat; height: 25px; width: 59px; " /> </td> </tr> </table> } </section> <div class="note"> * 不要在公共場(chǎng)合保存登錄信息;<br /> * 為了保證您的帳號(hào)安全,退出系統(tǒng)時(shí)請(qǐng)注銷登錄 <span id="msg_tip"></span> </div> </div>
以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!
相關(guān)文章
fckeditor粘貼Word時(shí)彈出窗口取消的方法
這篇文章主要介紹了fckeditor粘貼Word時(shí)彈出窗口取消的方法,是應(yīng)用fckeditor時(shí)非常實(shí)用的技巧,需要的朋友可以參考下2014-10-10整理Javascript函數(shù)學(xué)習(xí)筆記
整理Javascript函數(shù)學(xué)習(xí)筆記,之前一系列的文章是跟我學(xué)習(xí)Javascript,本文就是進(jìn)一步學(xué)習(xí)Javascript函數(shù),希望大家繼續(xù)關(guān)注2015-12-12js實(shí)現(xiàn)從中間開(kāi)始往上下展開(kāi)網(wǎng)頁(yè)窗口的方法
這篇文章主要介紹了js實(shí)現(xiàn)從中間開(kāi)始往上下展開(kāi)網(wǎng)頁(yè)窗口的方法,是非常實(shí)用的js窗口效果,需要的朋友可以參考下2015-03-03JavaScript地圖拖動(dòng)功能SpryMap的簡(jiǎn)單實(shí)現(xiàn)
SpryMap是一個(gè)獨(dú)立的并且是輕量級(jí)的JavaScript類庫(kù),它不依賴于任何其他的JS框架2013-07-07AJAX XMLHttpRequest對(duì)象創(chuàng)建使用詳解
這篇文章主要介紹了AJAX XMLHttpRequest對(duì)象創(chuàng)建使用詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-08-08javascript中mouseenter與mouseover的異同
javascript中mouseover和mouseenter的區(qū)別主要在于監(jiān)聽(tīng)對(duì)象的子元素是否觸發(fā)事件。mouseover:鼠標(biāo)移入監(jiān)聽(tīng)對(duì)象中,或者從監(jiān)聽(tīng)對(duì)象的一個(gè)子元素移入另一個(gè)子元素中時(shí)觸發(fā)該事件。mouseenter:鼠標(biāo)移入監(jiān)聽(tīng)對(duì)象時(shí)觸發(fā),在監(jiān)聽(tīng)對(duì)象內(nèi)移動(dòng)不會(huì)觸發(fā)。2017-06-06