jquery cookies to achieve a simple skin-changing function for small Web sites _jquery

Source: Internet
Author: User
Some time ago trying to use jquery cookies, do a simple skin-changing function, only for small sites and code low-level.

First introduce jquery and cookie Plug-ins
Copy Code code as follows:

<script type= "Text/javascript" src= "__public__/js/jquery.js" ></script>
<script type= "Text/javascript" src= "__public__/js/cookie.js" ></script>

Prepare several CSS files
Copy Code code as follows:

<link rel= "stylesheet" type= "Text/css" href= "__public__/css/basic2.css" id= "F" >

The body section of the Web page prepares several button buttons to trigger jquery
Copy Code code as follows:

<button> style one </button><button> style two </button>

jquery Code
Copy Code code as follows:

$ (document). Ready (function () {
$ ("#button1"). Click (
function () {
$.cookie (' Cssfile ', ' basic2.css ');
Location.reload (); Refresh Page
}
);
$ ("#button2"). Click (
function () {
$.cookie (' Cssfile ', ' basic.css ');
Location.reload ();
}
);
});
$ (document). Ready (
function () {
var file=$.cookie (' Cssfile '); Read cookies
if (typeof file== "undefined")
{
var cssfile= "__public__/css/basic2.css"; No settings, read default CSS
}
Else
{
var cssfile= "__public__/css/" +file; The cookie that has been set
}
$ ("#f"). attr ("href", cssfile);
}
);

Click to get jquery cookie Plugin
Click to get jquery or use jquery on Google or Microsoft hosting
Microsoft CDN:
-------------------------------------------------------------------------------
Copy Code code as follows:

<script src= "Http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js" ></script>

Google CDN:
--------------------------------------------------------------------------------
Copy Code code as follows:

<script src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" > </script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.