Home > Web Front-end > JS Tutorial > The simple skin-changing function implemented by jquery cookie is suitable for small websites_jquery

The simple skin-changing function implemented by jquery cookie is suitable for small websites_jquery

WBOY
Release: 2016-05-16 17:24:16
Original
770 people have browsed it

When I tried to use jquery cookies some time ago, I made a simple skin-changing function, which was only suitable for small websites and the code was low-level.

First introduce jquery and cookie plug-ins

Copy the code The code is as follows:




Prepare several css files
Copy code Code As follows:



Prepare several button buttons in the body part of the web page to trigger jquery
Copy the code The code is as follows:



jquery code
Copy code The code is as follows:

$(document).ready(function(){
$("#button1").click(
function(){
$.cookie('cssfile','basic2.css');//Save cookies
location.reload(); //Refresh the page
}
);
$("#button2").click(
function(){
$.cookie('cssfile','basic.css');
location.reload();
}
);
});
$(document).ready(
function(){
var file=$.cookie('cssfile'); //Read cookie
if(typeof file=="undefined")
{
var cssfile="__PUBLIC__/css/basic2.css"; //No setting, read default css
}
else
{
var cssfile="__PUBLIC__/css/" file; //Set cookies
}
$("#f").attr("href",cssfile);
}
);

Click to get jquery cookie plug-in
Click to get jqueryOr use jquery hosted by Google or Microsoft
Microsoft CDN:
------------------------------------------------ -------------------------------------
Copy code The code is as follows:



Google CDN:
------------------------- -------------------------------------------------- -----
Copy code The code is as follows:


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template