改變文章字體大小/背景顏色(含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事件實(shí)現(xiàn)改變文章字體大小</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>點(diǎn)擊上面的“大字體”,“中字體”,“小字體”,可以相應(yīng)改變字體大小。</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設(shè)置
{
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 "";
}
// 內(nèi)容樣式用戶定義
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);
}
}
//***
關(guān)鍵詞:字體,cookie,背景顏色
閱讀本文后您有什么感想? 已有 人給出評(píng)價(jià)!
- 1
- 1
- 1
- 1
- 1
- 1