开发html5页面切换,<HTML5程序开发范例宝典(韩旭著)>读书笔记之页面风格切换实例...

这个demo是可运行的,html和css都比较简单,主要是js部分会稍微复杂一点。 另外一定要确保引入的路径没有问题,比如我的文件是这样放的:

832e63d3691df3c5ac831dfcabfe97bb.png

html:

测试按钮

function writeCookie(cssPath){

//设置cookie的值为30天

var today=new Date();

var expires=new Date();

expires.setTime(today.getTime()+1000*60*60*24*30);//有效期为30天

var str="cssPath="+cssPath+";expires="+expires.toGMTString()+";";

document.cookie=str;

}

function readCookie(cookieName){

var search=cookieName+"=";

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));

}

}

}

}

//ifCookie(),初始化页面风格

function ifCookie(){

if(readCookie("cssPath")==undefined){//当标记网页style的cookie不存在

writeCookie("css/style1.css");

}

document.getElementById("myCss").href=readCookie("cssPath");

}

//change(),用于改变页面的整体风格

function change(myCss,cssPath){

writeCookie(cssPath);

document.getElementById(myCss).href=readCookie("cssPath");

}

style1.css

*{

margin:0;

padding:0;

box-sizing:border-box;

}

body

{

background-color:#fff;

font-size:18px;

font-family:"Arial","Tahoma","微软雅黑","雅黑";

line-height:18px;

padding:0px;

margin:0px;

text-align:center;

}

button

{

font-family:"Arial","Tahoma","微软雅黑","雅黑";

border:0px;

vertical-align:middle;

margin:8px;

line-height:18px;

font-size:18px;

}

.testBtn{

width:145px;

height:34px;

line-height:22px;

font-size:22px;

color:#959595;

padding-bottom:4px;

}

style2.css:

*{

margin:0;

padding:0;

box-sizing:border-box;

}

body

{

background-color:#fff;

font-size:18px;

font-family:"Arial","Tahoma","微软雅黑","雅黑";

line-height:18px;

padding:0px;

margin:0px;

text-align:center;

}

button

{

font-family:"Arial","Tahoma","微软雅黑","雅黑";

border:0px;

vertical-align:middle;

margin:8px;

line-height:18px;

font-size:18px;

}

.testBtn{

width:144px;

height:42px;

line-height:18px;

font-size:18px;

color:#ff6000;

padding-bottom:4px;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值