普通html 实现换肤

学习笔记 yekong 311℃

html

<!DOCTYPE html>
<html>  
  <head>
    <meta charset="utf-8">
    <title>Change backgrounIMG</title>
    <link href="css/default.css" rel="stylesheet" type="text/css" />
    <link href="css/skin_0.css" rel="stylesheet" type="text/css" id="cssfile" />
    <script src="js/jquery-1.3.1.js" type="text/javascript"></script>
    <script src="js/jquery.cookie.js" type="text/javascript"></script>
  </head>  
  <body>
    <ul id="skin">
      <li id="skin_0">大黄蜂</li>
      <li id="skin_1">擎天柱</li>
      <li id="skin_2">海贼王</li>
      <li id="skin_3">高达</li>
      <li id="skin_4">超梦</li></ul>
  </body>
</html>

js部分

$(function() {
    $('#skin li').click(function() {
        switchSkin(this.id)
    });
    var cookie_skin = $.cookie('MyCssSkin');
    if (cookie_skin) {
        switchSkin(cookie_skin);
    }
});
function switchSkin(skinName) {
    $('#cssfile').attr('href', 'css/' + skinName + '.css');
    $.cookie('MyCssSkin',skinName,{path:'/',expires:10});
    //$.cookie('MyCssSkin',skinName,{path:'/',expires:10});
}
喜欢 (1)