Home >Web Front-end >JS Tutorial >Description of how to use js (jquery) to operate cookies_jquery

Description of how to use js (jquery) to operate cookies_jquery

WBOY
WBOYOriginal
2016-05-16 17:08:091086browse

Cookie operation is a function we often use in web development. In the past, we usually implemented it through javascript. The following jquery plug-in is specially used for cookie operations

, including adding, clearing, reading cookies...
You can download it from the homepage of this plug-in: http://jquery.com/
When in After the jquery file and the plug-in file are referenced in the page, you can perform the following operations:

Set cookie
Set a cookie with name blog and value css9.net:
$.cookie("blog", "css9.net"); Set a cookie with name blog and value css9. net cookie, and set the expiration time (expires attribute) to 7 days:
$.cookie("blog", "css9.net", { expires: 7 }); Set a name to blog and a value to css9. net cookie, set the expiration time (expires attribute) to 7 days, the same as

Set the path attribute of the cookie to "/admin"
$.cookie("blog", "css9.net", { path: '/admin', expires: 7 }); Read Cookie:
Read the cookie value named blog:
alert( $.cookie("blog") ); delete cookie:
$.cookie("example", null);
Downloaded js file There is a more detailed explanation in

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn