動態CSS切換

來源:互聯網
上載者:User

//根據傳入的參數不同,使用不同的色彩配置:
// 優先順序是: url 參數優先順序最高、然後是cookies 值

// 從url 字串中提取變數的值
function GetQueryValue(sorStr,panStr)
{
 var vStr="";
 if (sorStr==null || sorStr=="" || panStr==null || panStr=="") return vStr;
 sorStr = sorStr.toLowerCase();
 panStr += "=";
 var itmp=sorStr.indexOf(panStr);
 if (itmp<0){return vStr;}
 sorStr = sorStr.substr(itmp + panStr.length);
 itmp=sorStr.indexOf("&");
 if (itmp<0)
 {
  return sorStr;
 }
 else
    {
  sorStr=sorStr.substr(0,itmp);
  return sorStr;
 }
}

function getcookieval(offset)  
{
 var endstr = document.cookie.indexOf(';',offset);
 if (endstr == -1) endstr = document.cookie.length;
 return unescape (document.cookie.substring(offset,endstr));
}

//從cookcie 中獲得
function getcookie(name)  
{
 var arg = name + '=';
 var alen = arg.length;
 var clen = document.cookie.length;
 var j = 0;
 while (j< clen)      
 {
  var k = j + alen;
  if(document.cookie.substring(j,k) == arg) return getcookieval(k);
  j = document.cookie.indexOf('',j)+1;
  if (j ==0 ) break;
 }
 return null;
}

// 獲得url字串
var strGetQuery = document.location.search;
// 獲得csdnstyle 參數的值
var stylevalue = GetQueryValue(strGetQuery,'csdnstyle')

// 如果url 中
if (stylevalue == '')
{
 stylevalue = getcookie('csdnstyle');
}
//alert(stylevalue);
//確定選擇的css
switch(stylevalue)
{
 case '1':
  document.write('<link rel="stylesheet" type="text/css" href="/Expert/style/1.css" >');
  break;
 case '2':
  document.write('<link rel="stylesheet" type="text/css" href="/Expert/style/2.css" >');
  break;
 case '3':
  document.write('<link rel="stylesheet" type="text/css" href="/Expert/style/3.css" >');
  break;
 case '4':
  document.write('<link rel="stylesheet" type="text/css" href="/Expert/style/4.css" >');
  break;
 default:
  document.write('<link rel="stylesheet" type="text/css" href="/Expert/style/0.css" >');
}

相關文章

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.