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

推荐订阅源

博客园 - Franky
N
Netflix TechBlog - Medium
Google Online Security Blog
Google Online Security Blog
月光博客
月光博客
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
腾讯CDC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
M
MIT News - Artificial intelligence
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
The Cloudflare Blog
Blog — PlanetScale
Blog — PlanetScale
F
Full Disclosure
G
Google Developers Blog
罗磊的独立博客
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
A
About on SuperTechFans
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队
GbyAI
GbyAI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
The Register - Security
The Register - Security
U
Unit 42
D
Docker
Martin Fowler
Martin Fowler
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
阮一峰的网络日志
阮一峰的网络日志
C
Cybersecurity and Infrastructure Security Agency CISA
博客园_首页
Google DeepMind News
Google DeepMind News

博客园 - Bobby

SQL Top注意事项 asp.net回车提交表单 - Bobby - 博客园 C#关于值类型和引用类型 Asp.Net XML操作基类(修改,删除,新增,创建) 项目中的代码 客户端全部选中或取消Repeater中的CheckBox - Bobby - 博客园 javascript技巧参考(转载) js倒计时关闭窗口&计算字数 - Bobby - 博客园 CSS控制GridView固定表头 - Bobby - 博客园 经典算法-C#四种排序算法 js简繁转换代码 ASP.NET错误处理的方式(总结) ASP.NET错误处理和程序优化 学习SQL应知道的动态SQL语句基本语法 js宝典学习笔记【转载】 在b/s开发中经常用到的javaScript技术整理 Visual C#常用函数和方法集汇总 SQL SERVER 与ACCESS、EXCEL的数据转换 不被浏览器屏蔽的对联广告
js设置调用cookie设置背景颜色 字号、颜色
Bobby · 2007-04-26 · via 博客园 - Bobby

var tfs=GetCookie('bookfs');
//字体大小
var tbg=GetCookie('bookbg');
//背景颜色
var tfc=GetCookie('bookfc');
//字体颜色

if (tfs != null){
document.write ('
<style type="text/css">');
document.write ('#text 
{  font-size: '+tfs+'px; }');
document.write ('
</style>');
}

if (tbg != null){
document.write ('
<style type="text/css">');
document.write ('body 
{  background-color: '+tbg+' }');
document.write ('
</style>');
}

if(tfc != null)
{
document.write('
<style type="text/css">');
document.write('#text 
{color:'+tfc+'}');
document.write ('
</style>');
}


function GetCookieVal(offset)
//获得Cookie解码后的值
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr 
= document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}


function SetCookie(name, value)
//设定Cookie值
{
var expires = new Date();
expires.setTime(expires.getTime() 
+ 12 * 30 * 24 * 60 * 60 * 1000);
document.cookie 
= name + "=" + value + ";expires=" + expires.toGMTString();
}


function DelCookie(name)
//删除Cookie
{
var exp = new Date();
exp.setTime (exp.getTime() 
- 1);
var cval = GetCookie (name);
document.cookie 
= name + "=" + cval + "; expires="+ exp.toGMTString();
}


function GetCookie(name)
//获得Cookie的原始值
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return GetCookieVal (j);
= document.cookie.indexOf(" ", i) + 1;
if (i == 0break;
}

return null;
}


function setfs(id){
document.getElementById('text').style.fontSize
=id+"px";
SetCookie('bookfs',id);
}


function setbg(id){
document.getElementsByTagName('body')[
0].style.backgroundColor=id;
SetCookie('bookbg',id);
}


function setfc(id)
{
document.getElementById('text').style.color 
= id;
SetCookie('bookfc',id);
}

以上为js代码保存为setstyle,以下为html调用

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">

{
    COLOR
: #4682b4
}

a:hover 
{
    COLOR
: #ff4500
}


#text 
{
    FONT-SIZE
: 16px; MARGIN: 5px auto 30px; WIDTH: 90%; LINE-HEIGHT: 180%; TEXT-ALIGN: left
}



}
.bg0 
{
    BACKGROUND
: #f2fafb
}

.bg1 
{
    BACKGROUND
: #e4ebf5 
}

.bg2 
{
    BACKGROUND
: #fbfbea 
}

.bg3 
{
    BACKGROUND
: #f4ebef
}

.bg4 
{
    BACKGROUND
: #ffffff
}

.fs0 
{
    FONT-SIZE
: 18px
}

.fs1 
{
    FONT-SIZE
: 14px
}

.fs2 
{
    FONT-SIZE
: 12px
}


}
</style>
<script type="text/javascript" src="setstyle.js"></script>
</head>
<body>
<div style="font-size: 12px; float: left; width: 98%; color: #000000; line-height: 30px;
                    font-family: Verdana, 宋体; text-align: right"
> &nbsp;<span class="tools">字体:<class="fs0" onclick="setfs('20')" href="javascript:void(0)"></a> <class="fs1" onclick="setfs('16')" href="javascript:void(0)"></a> <class="fs2"
                            onclick
="setfs('14')" href="javascript:void(0)"></a> 字体颜色:<class="fs2" onclick="setfc('#484848')"
                                href
="javascript:void(0)">黑色</a> <class="fs2" onclick="setfc('#4372a5')" href="javascript:void(0)"> 蓝色</a> <class="fs2" onclick="setfc('#505d71')" href="javascript:void(0)">蓝灰</a> <class="fs2" onclick="setfc('#d01f3c')" href="javascript:void(0)">红色</a> <class="fs2"
                            onclick
="setfc('#828282')" href="javascript:void(0)">灰色</a> &nbsp;&nbsp;&nbsp;&nbsp;背景:<a
                                
class="bg0" onclick="setbg('#f2fafb')" href="javascript:void(0)">绿色</a> <class="bg1" onclick="setbg('#e4ebf5')" href="javascript:void(0)">蓝色</a> <class="bg2"
                            onclick
="setbg('#fbfbea')" href="javascript:void(0)">黄色</a> <class="bg3" onclick="setbg('#f4ebef')"
                                href
="javascript:void(0)">粉红色</a> <class="bg4" onclick="setbg('#FFF')" href="javascript:void(0)"> 白色</a>&nbsp; </span> </div>
<div id="text">
显示内容
</div>
</body>
</html>