//
function sizeInit(){
var fsize=getCookie("fsize");
if(fsize>15){
changeColor(0);
}else{
changeColor(1);
}
var objs=document.getElementsByName("content_show");
for(i=0;i<objs.length;i++){
objs[i].style.fontSize=fsize+‘px‘;
}
}
//通过cookie fsize的值设置文章字体的大小
function setfont(o,f){
setCookie("fsize", f); //设置cookie
sizeInit();
}
//变色
function changeColor(c){
var objs=document.getElementsByName("middle_size");
var objs1=document.getElementsByName("big_size"); //得到一个数组
if(c==0){
for(i=0;i<objs.length;i++){
$(objs[i]).addClass(‘fore‘); //把js转变为jquery对象 $(xx)
}
for(i=0;i<objs1.length;i++){
$(objs1[i]).removeClass(‘fore‘);
}
}else{
for(i=0;i<objs.length;i++){
$(objs[i]).removeClass(‘fore‘);
}
for(i=0;i<objs1.length;i++){
$(objs1[i]).addClass(‘fore‘);
}
}
}
//设置
function setCookie(name, value) {
var date = new Date();
date.setTime(date.getTime()+(7*24*600000));
var expires = "; expires="+date.toGMTString();
document.cookie = name+"="+value+expires+"; path=/";// name=23;expires=60000;path=/
}
//获取
function getCookie(s){
var fsize=15;
if(document.cookie.length>0){
c_start=document.cookie.indexOf(s + "=");
if (c_start!=-1){
c_start=c_start + s.length+1;
c_end=document.cookie.indexOf(";",c_start);
if(c_end==-1)c_end=document.cookie.length;
fsize=unescape(document.cookie.substring(c_start,c_end));
return fsize;
}
}
return fsize;
}
html
<span class="fore2">字号
<a href="javascript:void(0)" name="middle_size" >中</a>
<a href="javascript:void(0);" class="fore" name="big_size">大</a>
</span>