jquery Cookie Plugin Implementation saves user login information _jquery

Source: Internet
Author: User
Copy Code code as follows:

<! DOCTYPE html>
<title>cookies.html</title>

<meta http-equiv= "keywords" content= "keyword1,keyword2,keyword3" >
<meta http-equiv= "description" content= "This are my page" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">

<style type= "Text/css" >
. txt{
width:150px;
height:20px;
BORDER:1PX Blue Solid;
Border-radius:0.5em;
margin-bottom:5px;
padding-left:5px;
}

</style>
<script type= "Text/javascript" src= ". /js/jquery-1.10.2.js "></script>
<script type= "Text/javascript" src= ". /js/jquery.cookie.js "></script>
<script type= "Text/javascript" >
$ (function () {


if ($.cookie ("name")) {
Value is assigned if present
$ ("#username"). Val ($.cookie ("name"));

}


$ ("#mycookie"). Submit (function () {

If you select the Save User name option
if ($ ("#chkSave"). Is (": Checked")) {

Set cookie Value
$.cookie ("Name", $ ("#username"). Val (), {
expires:7,//Set Save time
Path: "/"//Set the saved path

});

}else{

Destroying objects
$.cookie ("name", null,{
Path: "/"

});
}

return false;
});

});


</script>
<body>
<form action= "#" method= "Get" id= "MyCookie" >

<div>
User name:<br>
<input id= "username" name= "username" type= "text" class= "TXT" >
</div>
<div>
Password:<br>
<input id= "password" name= "password" type= "password" class= "TXT" >
</div>
<div>
<input id= "Chksave" type= "checkbox" > whether to save the user name
</div>
<div>
<input id= "cookbtn" class= "BTN" type= "Submit" value= "submitted" >
</div>

</form>
</body>

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.