(jQuery) Cookie remembers user name and password

Source: Internet
Author: User
Original: http://blog.sina.com.cn/s/blog_6bb8eaaa0101a9ta.html
(jQuery) cookie remembers user name and password(2013-10-22 08:55:33) reprinted
Tags: jquery Web front-end remember user name password Category: "Web Front End"
function: Check "Remember user name", click Login, save cookies, the next login does not need to enter, do not tick "Remember user name", click Login, do not save cookies, the next login needs to enter;

jquery Code:

<script src= "Js/jquery-1.3.1.js" type= "Text/javascript" ></script> <!--introduce library files referencing jquery---
<script src= "Js/jquery.cookie.js" type= "Text/javascript" ></script> <!--introduction of jquery Cookie Plugin--


<script type= "Text/javascript" >

Verify that the password is remembered when the page is initialized
$ (document). Ready (function () {
if ($.cookie ("rmbuser") = = "true") {
$ ("#rmbUser"). attr ("Checked", true);
$ ("#wsc-username"). Val ($.cookie ("username"));
$ ("#wsc-password"). Val ($.cookie ("password"));
}
});


function Saveuserinfo () {
if ($ ("#rmbUser"). attr ("checked") = = True) {
var userName = $ ("#wsc-username"). Val ();
var PassWord = $ ("#wsc-password"). Val ();
$.cookie ("Rmbuser", "true", {expires:7}); Store a cookie with a 7-day period
$.cookie ("UserName", UserName, {expires:7}); Store a cookie with a 7-day period
$.cookie ("PassWord", PassWord, {expires:7}); Store a cookie with a 7-day period
}
else {
$.cookie ("Rmbuser", "false", {Expires:-1}); Delete Cookies
$.cookie ("UserName", "', {Expires:-1});
$.cookie ("PassWord", "', {Expires:-1});
}
}
</script>


HTML code:

<body>
<form action= "" method= "POST" >
<div class= "Form" >

<div id= "J_username" class= "Loginitem" >
<label> User name:</label>
<input maxlength= "value=" "Name=" U_username "class=" Log_field "id=" Wsc-username ">
</div>

<div class= "Loginitem" id= "J_password" >
<label> Secret &nbsp;&nbsp; Code:</label>
<input type= "Password" value= "maxlength=" "Name=" U_pwd "class=" Log_field "id=" Wsc-password ">
</div>

<div class= "Loginremember" >
<input type= "checkbox" checked= "true" Name= "Chkrememberusername" class= "checkbox" id= "Rmbuser" >
<label for= "Rmbuser" > Remember user name </label>
<a href= "#" > Forgot password?</a>
</div>

<div class= "Loginitem Loginbutton" id= "Wait" >
<input type= "Submit" value= "Login" onclick= "Saveuserinfo ()" class= "button" id= "Log_commit" >
</div>

</div><!--Form Div-->
</form>

-------------------------------------------------------------------------------------below is the Jquery.cookie.js usage

$.cookie (' The_cookie '); Get cookies

$.cookie (' The_cookie ', ' the_value '); Set cookies

$.cookie (' The_cookie ', ' The_value ', {expires:7}); Set a cookie with time

$.cookie (' The_cookie ', ', {Expires:-1}); Delete

$.cookie (' The_cookie ', null);  Delete Cookie $.cookie (' The_cookie ', ' The_value ', {expires:7, path: '/', Domain: ' jquery.com ', secure:true});//Create a new cookie Include validity path domain name, etc.

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.