<> It is introduced in another article js The origin of cookie Application mode , What's been used recently at work jquery Of cookie plug-in unit , Here is an introduction , Promise to learn in a minute .
One , introduce jq Related documents
stay html Introduce the required files into the file , as follows :
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script> <script
type="text/javascript" src="js/jquery.cookie.js"></script>
Two ,js Set in cookie
stay js Set in cookie:
cookieName------- Set the cookie A name ;
cookieValue------- Give Way cookie The value you want to save , for example :$("#password").val();
{ expires: 7 }------- set up cookie Valid time of 7 day , The time is set by ourselves .
Select one of the following three lines to use :
// set up cookie function setCookie(){ $.cookie("cookieName", "cookieValue", {
expires: 7 });// The first kind $.cookie('the_cookie', 'the_value', { expires: 7, path: '/'
});// The second kind , Add path $.cookie("COOKIE_PASSWORD", $("#password").val(), "/",1/144);// Examples
}
Three , read cookie
Direct access cookie value , if cookie If it exists, the saved ’cookieValue’; if cookie Return if it does not exist null
// read cookie function getCookie(){ var cookieWord=$.cookie("cookieName"); }
Four , Call method
The setting and reading methods are finished , Call the method directly where you need it .
Technology
Daily Recommendation