Javascript實(shí)現(xiàn)登錄記住用戶名和密碼功能
更新時間:2017年03月22日 17:24:56 作者:Resources
本文主要介紹了Javascript實(shí)現(xiàn)登錄記住用戶名和密碼功能的代碼。具有很好的參考價值。下面跟著小編一起來看下吧
話不多說,請看代碼:
<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"));
}
})
//寫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">賬 號:</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">
* 不要在公共場合保存登錄信息;<br />
* 為了保證您的帳號安全,退出系統(tǒng)時請注銷登錄
<span id="msg_tip"></span>
</div>
</div>
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
相關(guān)文章
整理Javascript函數(shù)學(xué)習(xí)筆記
整理Javascript函數(shù)學(xué)習(xí)筆記,之前一系列的文章是跟我學(xué)習(xí)Javascript,本文就是進(jìn)一步學(xué)習(xí)Javascript函數(shù),希望大家繼續(xù)關(guān)注2015-12-12
js實(shí)現(xiàn)從中間開始往上下展開網(wǎng)頁窗口的方法
這篇文章主要介紹了js實(shí)現(xiàn)從中間開始往上下展開網(wǎng)頁窗口的方法,是非常實(shí)用的js窗口效果,需要的朋友可以參考下2015-03-03
JavaScript地圖拖動功能SpryMap的簡單實(shí)現(xiàn)
SpryMap是一個獨(dú)立的并且是輕量級的JavaScript類庫,它不依賴于任何其他的JS框架2013-07-07
AJAX XMLHttpRequest對象創(chuàng)建使用詳解
這篇文章主要介紹了AJAX XMLHttpRequest對象創(chuàng)建使用詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-08-08
javascript中mouseenter與mouseover的異同
javascript中mouseover和mouseenter的區(qū)別主要在于監(jiān)聽對象的子元素是否觸發(fā)事件。mouseover:鼠標(biāo)移入監(jiān)聽對象中,或者從監(jiān)聽對象的一個子元素移入另一個子元素中時觸發(fā)該事件。mouseenter:鼠標(biāo)移入監(jiān)聽對象時觸發(fā),在監(jiān)聽對象內(nèi)移動不會觸發(fā)。2017-06-06

