JQuery记住客商名和密码的求实落到实处

复制代码 代码如下:

复制代码 代码如下:

JQuery Code 复制代码 代码如下: $.ready{ if == "true") { $.prop; $.val; $; $.append(""); $.val; } $.click{ if; } }); }); //记住用户名密码 function save() { if .prop { var username = $; var password = $; $.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 = $; var password = $; if(username == "" || username == "请输入用户名"){ $.text; $; return false; } if(password == "" || password == "请输入密码"){ $.text; $; return false; } $; return true; } function login(){ $.ajax({ type:"POST", url: "login!loginValidate.action", data:{userName:$,password:$}, dataType:"json", beforeSend: function; }, success:function{ if{ addCookie("userName", $, 0); save(); location.href = "/index.jsp"; }else{ $; $.text; return false; } } }); }

<div>
<input id="username" type="text" class="txt1" value="请输入用户名" onclick="if(this.value=='请输入用户名'){this.value=''; }" onfocus="if(this.value=='请输入用户名'){this.value=''; }" />
<input id="password" type="text" class="txt2" value="请输入密码" onclick="if(this.value=='请输入密码'){this.value='';this.type='password';}" onfocus="if(this.value=='请输入密码'){this.value='';this.type='password';}"/>
</div>

JQuery Code

复制代码 代码如下:

$(document).ready(function(){
if ($.cookie("rmbUser") == "true") {
$("#ck_rmbUser").prop("checked", true);
$("#username").val($.cookie("username"));
$("#password").remove();
$("#pass").append("<input id='password' type='password' class='txt2'/>");
$("#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;
}

}
});
}

代码如下: div input id="username" type="text" class="txt1" value="请输入用户名" onclick="if(this.value=='请输入用户名'){this.value=''; }" onfocus="if(t...

本文由澳门威斯尼人平台登录发布于服务器&运维,转载请注明出处:JQuery记住客商名和密码的求实落到实处

相关阅读