jquery代碼
$(document).ready(function(){
if ($.cookie("rmbUser") == "true") {
$("#ck_rmbUser").prop("checked", true);
$("#username").val($.cookie("username"));
$("#password").remove();
$("#pass").append("");
$("#password").val($.cookie("password"));
}
$("#loginButton").click(function(){
if(check()){
login();
}
});
});
//記住用戶名密碼
function save() {
if ($("#ck_rmbUser").prop("checked")) {
var username = $("#username").val();
var password = $("#password").val();
$.cookie("rmbUser", "true", { expires: 7 }); //存儲一個帶7天期限的cookie
$.cookie("username", username, { expires: 7 });
$.cookie("password", password, { expires: 7 });
}else{
$.cookie("rmbUser", "false", { expire: -1 });
$.cookie("username", "", { expires: -1 });
$.cookie("password", "", { expires: -1 });
}
};
function check(){
var username = $("#username").val();
var password = $("#password").val();
if(username == "" || username == "請輸入用戶名"){
$("#tip").text("請輸入用戶名!");
$("#username").focus();
return false;
}
if(password == "" || password == "請輸入密碼"){
$("#tip").text("請輸入密碼!");
$("#password").focus();
return false;
}
$("#tip").text("");
return true;
}
function login(){
$.ajax({
type:"POST",
url: "login!loginValidate.action",
data:{userName:$("#username").val(),password:$("#password").val()},
dataType:"json",
beforeSend: function(){
showOverlay();
},
success:function(data){
if(data.success){
addCookie("userName", $("#username").val(), 0);
save();
location.href = "/index.jsp";
}else{
$("#overlay").hide();
$("#tip").text("用戶名或密碼錯誤,請重新登錄!");
return false;
}
}
});
}
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com