Javascript實現(xiàn)登錄記住用戶名和密碼功能
更新時間:2017年03月22日 17:24:56 作者:Resources
本文主要介紹了Javascript實現(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)容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
相關文章
Elasticsearch工具cerebro的安裝與使用教程
這篇文章主要介紹了Elasticsearch工具cerebro的安裝與使用教程,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-03-03
javascirpt實現(xiàn)2個iframe之間傳值的方法
這篇文章主要介紹了javascirpt實現(xiàn)2個iframe之間傳值的方法,涉及javascript針對iframe框架下的頁面元素操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下2016-06-06
Javascript實現(xiàn)滑塊滑動改變值的實現(xiàn)代碼
一個功能,值得一說的是本頁面的滑塊實現(xiàn)由于對美工不是很熟悉所以上圖了,感興趣的朋友可以了解下哈2013-04-04

