$(document).ready(function(){
//Login Aciton
$("#login").bind("click", function () {
var username = $("#username").val();
var password = $("#password").val();
if(username == ""){
alert("请输入用户名!");
return;
}
if(password == ""){
alert("请输入密码!");
return;
}
<%--var s = "";--%>
<%--s += "{";--%>
<%--s += "username:'" + username + "',password:'" + password;--%>
<%--s += "'}";--%>
<%--arr = eval('(' + s + ')');--%>
<%--$.post("<%=request.getContextPath()%>/login.asp", arr, function(data){--%>
<%--if(data == 1){--%>
<%--location.replace("<%=path %>/page/index.jsp");--%>
<%--}else{--%>
<%--location.replace("<%=path %>/page/fail.jsp");--%>
<%--}--%>
<%--});--%>
$("#loginForm").submit(); //form表单提交
});
if ($.cookie("automaticLogin") == "true") {
$("#automaticLogin").attr("checked", true);
$("#rememberMe").attr("checked", true);
$("#username").val($.cookie("usernameCookie"));
$("#password").val($.cookie("passwordCookie"));
$("#login").click();
}
if ($.cookie("rememberMe") == "true") {
$("#rememberMe").attr("checked", true);
$("#username").val($.cookie("usernameCookie"));
$("#password").val($.cookie("passwordCookie"));
}
//Automatic Login Checkbox
$("#automaticLogin").bind("click", function () {
if($(this).is(":checked") == true){
// 存储一个带7天期限的 cookie
$.cookie("automaticLogin", "true", { expires: 7 });
$.cookie("rememberMe", "true", { expires: 7 });
$.cookie("usernameCookie", $("#username").val(),{expires:7});
$.cookie("passwordCookie", $("#password").val(),{expires:7});
}else{
$.cookie("automaticLogin", "false", { expires: -1 });
}
});
//Remember Password Checkbox
$("#rememberMe").bind("click", function () {
if($(this).is(":checked") == true){
// 存储一个带7天期限的 cookie
$.cookie("rememberMe", "true", { expires: 7 });
$.cookie("usernameCookie", $("#username").val(),{expires:7});
$.cookie("passwordCookie", $("#password").val(),{expires:7});
}else{
$.cookie("automaticLogin", "false", { expires: -1 });
$.cookie("rememberMe", "false", { expires: -1 });
$.cookie("usernameCookie", '', { expires: -1 });
$.cookie("passwordCookie", '', { expires: -1 });
}
});
});
因为用到cookie所以要导入jquery.cookie.js