[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<> 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 .