Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize skin change function based on cookie in jQuery

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to achieve skin change function based on cookie in jQuery". In daily operation, I believe that many people have doubts about how to achieve skin change function based on cookie in jQuery. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubt of "how to achieve skin change function based on cookie in jQuery". Next, please follow the editor to study!

Code:

The use of cookie. HuanFu {float:right;}. HuanFu ul li {width:30px;height:30px; list-style:none; margin:0 5px; float:left; cursor:pointer; border:1px solid # 000;} .fu1 {background-color:#F00;} .fu2 {background-color:#0F0;} .fu3 {background-color:#00F;} .fu4 {background-color:#FF0;}. HuanFu ul li.select {border:3px solid # 000 } $(function () {var cookieClass=getCookie ('class'); / / read the local Cookie if (cookieClass) {$("body") .attr ("class", cookieClass); / / restore the background of the page to the color saved by Cookie} else {$("body") .attr ("class", "fu1") } $(".huanFu ul li") .on ("click", function () {$(this) .addClass ("select"). Siblings () .removeClass ("select"); / / Mark the selected style var fuName=$ (this) .attr ("fuName"); / / get the class name. Explanation: a fuName attribute is created and fu1 is stored in it, but now it is only $("body"). Attr ("class", fuName); / / change the class attribute of body to achieve the effect of background color change function SetCookie (name,value,day) {/ / three values passed, name, value, number of days saved var exp = new Date () / / get the current local time (including date) exp.setTime (exp.getTime () + day*24*60*60*1000); / / save the number of days in milliseconds [xss_clean] = name + "=" + escape (value) + "; expires=" + exp.toGMTString (); / / with name=fu1 Expires=Date {Thu Jun 26 2014 23:23:25 GMT+0800} this long string is saved to the local cookie} SetCookie ("class", fuName,7); / / sets the Cookie procedure}); function getCookie (name) {/ / reads the local Cookie procedure var nameTit=name+ "="; / / the name value at this time is "class", nameTit= "class=" var ca= [XSS _ clean] .split (';'); / / read the content of the local cookie is "xxx.xxx" Xxx.xxx ", so when we remove the';', it will be stored in the ca as an array. For (var iTuno Bandi)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report