Home >Web Front-end >JS Tutorial >jQuery Set Get Delete Cookies Example

jQuery Set Get Delete Cookies Example

Christopher Nolan
Christopher NolanOriginal
2025-03-07 00:13:09376browse

jQuery Set Get Delete Cookies Example $(function($) { function displayMessage(msg) { $('#message').html(msg).css({color: 'green'}); } displayMessage('jQuery cookie plugin test'); $('#setSessionCookie').click(function() { $.cookie('test', 'Hmmm, cookie'); displayMessage("Cookie 'test' has been set."); }); $('#setCookie').click(function() { $.cookie('test', 'Hmmm, cookie', { expires: 7 }); displayMessage("Cookie 'test' has been set and will expire in 7 days."); }); $('#getCookie').click(function() { displayMessage("The value of the cookie named 'test' is: " $.cookie('test')); }); $('#deleteCookie').click(function() { $.cookie('test', null); displayMessage("Cookie 'test' has been deleted."); }); $('#testCookiesEnabled').click(function() { $.cookie('testcookiesenabled', null); $.cookie('testcookiesenabled', 'enabled'); if ($.cookie('testcookiesenabled')) { displayMessage("Cookie: " $.cookie('testcookiesenabled')); } else { displayMessage("Cookies disabled"); $.cookie('testcookiesenabled', null); } }); });

The above is the detailed content of jQuery Set Get Delete Cookies Example. For more information, please follow other related articles on the PHP Chinese website!

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