Copy Code code as follows:
<div>
<input id= "username" type= "text" class= "txt1" value= "Please enter the username" onclick= "if (this.value== ' Please enter user name ') {this.value= ';} Onfocus= "if (this.value== ' Please enter user name ') {this.value= ';}"/>
<input id= "Password" type= "text" class= "txt2" "value=" Please enter the password "onclick=" if (this.value== ' Please enter password ') {this.value= '; this.type= ' password ';} Onfocus= "if (this.value== ' Please enter password ') {this.value= '; this.type= ' password ';}" />
</div>
JQuery Code
Copy Code code as follows:
$ (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 ();
}
});
});
Remember user name password
function Save () {
if ($ ("#ck_rmbUser"). Prop ("checked")) {
var username = $ ("#username"). Val ();
var password = $ ("#password"). Val ();
$.cookie ("Rmbuser", "true", {expires:7}); Store a cookie with a period of 7 days
$.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 = "Please enter user name") {
$ ("#tip"). Text ("Please enter username!");
$ ("#username"). focus ();
return false;
}
if (password = = "" | | Password = "Please enter password") {
$ ("#tip"). Text ("Please enter password!");
$ ("#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 ("User name or password error, please login again!") ");
return false;
}
}
});
}