改变文章字体大小/背景颜色(含cookie控制)
1、
<script language=javascript>
var newasp_fontsize=9;
var newasp_lineheight=12;
</script>
<a style="CURSOR: hand; POSITION: relative" onclick="if(newasp_fontsize>8){NewaspContentLabel.style.fontSize=(--newasp_fontsize)+"pt";NewaspContentLabel.style.lineHeight=(--newasp_lineheight)+"pt";}" title="减小字体"><img src="/images/1.gif" border="0" width="15" height="15"><font color="#FF6600">减小字体</font></a>
<a style="CURSOR: hand; POSITION: relative" onclick="if(newasp_fontsize<64){NewaspContentLabel.style.fontSize=(++newasp_fontsize)+"pt";NewaspContentLabel.style.lineHeight=(++newasp_lineheight)+"pt";}" title="增大字体"><img src="/images/2.gif" border="0" width="15" height="15"><font color="#FF6600">增大字体</font></a>
<div id="NewaspContentLabel">
大小
</div>
2、<HTML>
<HEAD>
<STYLE type="text/css">
.bfont {font-size:20px;}
.nfont {font-size:16px;}
.sfont {font-size:12px;}
.cdiv {font-size:12px;}
.cdiv span {cursor:hand;text-decoration:underline;color:blue;}
</STYLE>
<TITLE> 用onclick事件实现改变文章字体大小</TITLE>
</HEAD>
<BODY id = pgcontent class = nfont>
<div class = cdiv>
<span onclick= "pgcontent.className='bfont';">大字体</span> |
<span onclick= "pgcontent.className='nfont';">中字体</span> |
<span onclick= "pgcontent.className='sfont';">小字体</span>
</div>
<p>点击上面的“大字体”,“中字体”,“小字体”,可以相应改变字体大小。</p>
</BODY></HTML>
3、
<script language="JavaScript">
function doZoom(size){
document.getElementById('zoom').style.fontSize=size+'pt'
}
// -->
</script>
<div id="zoom">改变字体大小</div>
[<a href="javascript:doZoom(12)">大字体</a>
<a href="javascript:doZoom(10.5)">中字体</a>
<a href="javascript:doZoom(9)">小字体</a>]
4、加入cookie控制
function setCookie(name, value) //cookies设置
{
var argv = setCookie.arguments;
var argc = setCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
if(expires!=null){
var LargeExpDate = new Date ();
LargeExpDate.setTime(LargeExpDate.getTime() + (expires*1000*3600*24));
}
document.cookie = name + "=" + escape (value) + "; path=/;" +((expires == null) ? "" : (" expires=" +LargeExpDate.toGMTString()));
}
function getCookie(Name) //cookies读取
{
var search = Name + "=";
if(document.cookie.length > 0){
offset = document.cookie.indexOf(search);
if(offset != -1) {
offset += search.length;
end = document.cookie.indexOf(";", offset);
if(end == -1){
end = document.cookie.length;
}
return unescape(document.cookie.substring(offset, end));
}
}
return "";
}
// 内容样式用户定义
function ContentSize(size)
{
var obj=document.getElementById("content");
obj.style.fontSize=size>0 ? size+"px" : "";
if (arguments.length==1){
setCookie("iwmsFontSize",size,size==0?-1:1);
}
}
function ContentBg(color)
{
var obj=document.getElementById("bodyTd");
obj.style.backgroundColor=color;
if (arguments.length==1){
setCookie("iwmsContBg",color,color.length==0?-1:1);
}
}
function InitContStyle()
{
var v=getCookie("iwmsFontSize");
if (v.length>0){
ContentSize(v,false);
}
v=getCookie("iwmsContBg");
if (v.length>0){
ContentBg(v,false);
}
}
//***
关键词:字体,cookie,背景颜色
阅读本文后您有什么感想? 已有 人给出评价!
- 1
- 1
- 1
- 1
- 1
- 1