惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
F
Full Disclosure
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Engineering at Meta
Engineering at Meta
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Threatpost
I
Intezer
V2EX - 技术
V2EX - 技术
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
小众软件
小众软件
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
N
News | PayPal Newsroom
MyScale Blog
MyScale Blog
AI
AI
Vercel News
Vercel News
Spread Privacy
Spread Privacy
美团技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
U
Unit 42
L
LangChain Blog
Recent Announcements
Recent Announcements

博客园 - wddavid

明天要回老家了,发一张阳台上最后的夕阳 【转载】淘宝百度之争 易博士这个可悲的品牌 枪手无数 必亡 【WDDAVID独家评测】金鹏E1191评测 【转载】把自己打造成一张"活名片" 企业网站建设中常用的英文翻译 【转载】发传单的艺术 【转帖】CorelDraw快捷键的使用大全 司马懿 【转载】Photoshop快捷键和技巧大全 新一代电子书汇总介绍,想入手了 继续做下去还是转行? 正则表达式30分钟教程 [Serializable]在C#中的作用-NET 中的对象序列化 常见尺寸LCD液晶显示器点距一览 block(块元素)、inline(内联元素) DIV+CSS小技巧随写 CSS中的expression Marquee为什么不符合WEB标准?
多风格选择 样式实时切换
wddavid · 2007-03-26 · via 博客园 - wddavid

首先是javascript代码:

function setActiveStyleSheet(title) {
  
var i, a, main;
  
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    
if(a.getAttribute("rel").indexOf("style"!= -1 && a.getAttribute("title")) {
      a.disabled 
= true;
      
if(a.getAttribute("title"== title) a.disabled = false;
    }
  }
}
function getActiveStyleSheet() {
  
var i, a;
  
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    
if(a.getAttribute("rel").indexOf("style"!= -1 && a.getAttribute("title"&& !a.disabled) return a.getAttribute("title");
  }
  
return null;
}
function getPreferredStyleSheet() {
  
var i, a;
  
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    
if(a.getAttribute("rel").indexOf("style"!= -1
       
&& a.getAttribute("rel").indexOf("alt"== -1
       
&& a.getAttribute("title")
       ) 
return a.getAttribute("title");
  }
  
return null;
}
function createCookie(name,value,days) {
  
if (days) {
    
var date = new Date();
    date.setTime(date.getTime()
+(days*24*60*60*1000));
    
var expires = "; expires="+date.toGMTString();
  }
  
else expires = "";
  documents.cookie 
= name+"="+value+expires+"; path=/";
}
function readCookie(name) {
  
var nameEQ = name + "=";
  
var ca = documents.cookie.split(';');
  
for(var i=0;i < ca.length;i++) {
    
var c = ca[i];
    
while (c.charAt(0)==' ') c = c.substring(1,c.length);
    
if (c.indexOf(nameEQ) == 0return c.substring(nameEQ.length,c.length);
  }
  
return null;
}

window.onload 

= function(e) {
  
var cookie = readCookie("style");
  
var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload 

= function(e) {
  
var title = getActiveStyleSheet();
  createCookie(
"style", title, 365);
}
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

然后把所有的样式表引入文档中:

<link rel="stylesheet"  type="text/CSS" href="css.css"  />
<link rel="stylesheet" type="text/CSS" href="aaa.css" title="aaa" />
<link rel="stylesheet" type="text/CSS" href="bbb.css" title="bbb" />

切换样式的按钮如下写:

<href="#" onclick="setActiveStyleSheet('',1); return false;">默认样式-白色</a>
<href="#" onclick="setActiveStyleSheet('aaa',1); return false;">样式一-蓝色</a>
<href="#" onclick="setActiveStyleSheet('bbb',1); return false;">样式二-橙色</a>