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)注銷(xiāo)登錄
<span id="msg_tip"></span>
</div>
</div>
以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!
相關(guān)文章
js腳本實(shí)現(xiàn)數(shù)據(jù)去重
最近在一個(gè)項(xiàng)目中,需要去除掉重復(fù)的數(shù)據(jù),之前都是在后臺(tái)實(shí)現(xiàn),現(xiàn)在客戶需求是在前臺(tái)去重,于是就想到了javascript腳本。2014-11-11
JS解決position:sticky的兼容性問(wèn)題的方法
本篇文章主要介紹了JS解決position:sticky的兼容性問(wèn)題的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10
Elasticsearch工具cerebro的安裝與使用教程
這篇文章主要介紹了Elasticsearch工具cerebro的安裝與使用教程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-03-03
快速解決bootstrap下拉菜單無(wú)法隱藏的問(wèn)題
今天小編就為大家分享一篇快速解決bootstrap下拉菜單無(wú)法隱藏的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-08-08
javascirpt實(shí)現(xiàn)2個(gè)iframe之間傳值的方法
這篇文章主要介紹了javascirpt實(shí)現(xiàn)2個(gè)iframe之間傳值的方法,涉及javascript針對(duì)iframe框架下的頁(yè)面元素操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06
小程序?qū)崿F(xiàn)簡(jiǎn)單驗(yàn)證碼倒計(jì)時(shí)
這篇文章主要為大家詳細(xì)介紹了小程序?qū)崿F(xiàn)簡(jiǎn)單驗(yàn)證碼倒計(jì)時(shí),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07
Javascript實(shí)現(xiàn)滑塊滑動(dòng)改變值的實(shí)現(xiàn)代碼
一個(gè)功能,值得一說(shuō)的是本頁(yè)面的滑塊實(shí)現(xiàn)由于對(duì)美工不是很熟悉所以上圖了,感興趣的朋友可以了解下哈2013-04-04
js實(shí)現(xiàn)登錄時(shí)記住密碼的方法分析
這篇文章主要介紹了js實(shí)現(xiàn)登錄時(shí)記住密碼的方法,結(jié)合實(shí)例形式分析了JavaScript基于cookie實(shí)現(xiàn)存儲(chǔ)登錄密碼相關(guān)操作技巧,需要的朋友可以參考下2020-04-04

