jquery remembers the specific implementation of username and password _jquery

Source: Internet
Author: User
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;
}

}
});
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.