JQuery's cookie plug-in stores user login information

Source: Internet
Author: User

Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Title> cookies.html </title>

<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "description" content = "this is 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 ")){
// If the value exists, the value is assigned.
$ ("# Username"). val ($. cookie ("name "));

}


$ ("# Mycookie"). submit (function (){

// If the Save User Name option is selected
If ($ ("# chkSave"). is (": checked ")){

// Set the Cookie value
$. Cookie ("name", $ ("# username"). val (),{
Expires: 7, // set the retention period
Path: "/" // set the saved path

});

} Else {

// Destroy the object
$. Cookie ("name", null ,{
Path :"/"

});
}

Return false;
});

});


</Script>
</Head>
<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 = "submit">
</Div>

</Form>
</Body>
</Html>

Related Article

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.