首页 » 建站技术 » 浏览内容

网站风格切换最新版 (Style Sheet Switcher)


2005-12-31 16:26:28 5,221 0 发表评论 字体: 作者:C.K.

体验版 88 元,个人版 128 元,多用户版 288元个人版160元升级到多用户版。

这个网站风格切换除了带记忆功能外,还可设定保持时间,比如5天或者180天,过了时间就自动恢复到默认样式表。

样式表连接

脚本作者:dynamicdrive.com

调用

默认风格
橙色风格
蓝色风格

脚本(另存为styleswitch.js)

程序代码:

//Style Sheet Switcher version 1.0 Nov 9th, 2005
//Author: Dynamic Drive: http://www.dynamicdrive.com
//Usage terms: http://www.dynamicdrive.com/notice.htm

function getCookie(Name) {
var re=new RegExp(Name+”=[^;]+”, “i”); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split(“=”)[1] //return its value
return null
}

function setCookie(name, value, days) {
var expireDate = new Date()
//set “expstring” to either future or past date, to set or delete cookie, respectively
var expstring=(typeof days!=”undefined”)? expireDate.setDate(expireDate.getDate()+parseInt(days)) : expireDate.setDate(expireDate.getDate()-5)
document.cookie = name+”=”+value+”; expires=”+expireDate.toGMTString()+”; path=/”;
}

function deleteCookie(name){
setCookie(name, “moot”)
}

function setStylesheet(title) {
var i, cacheobj
for(i=0; (cacheobj=document.getElementsByTagName(“link”)[ i ]); i++) {
if(cacheobj.getAttribute(“rel”).indexOf(“style”) != -1 && cacheobj.getAttribute(“title”)) {
cacheobj.disabled = true
if(cacheobj.getAttribute(“title”) == title)
cacheobj.disabled = false //enable chosen style sheet
}
}
}

function chooseStyle(styletitle, days){
if (document.getElementById){
setStylesheet(styletitle)
setCookie(“mysheet”, styletitle, days)
}
}

function indicateSelected(element){ //Optional function that shows which style sheet is currently selected within group of radio buttons or select menu
var i
if (selectedtitle!=null && (element.type==undefined || element.type==”select-one”)){ //if element is a radio button or select menu
var element=(element.type==”select-one”) ? element.options : element
for (i=0; iif (element[ i ].value==selectedtitle){ //if match found between form element value and cookie value
if (element[ i ].tagName==”OPTION”) //if this is a select menu
element[ i ].selected=true
else //else if it's a radio button
element[ i ].checked=true
break
}
}
}
}

var selectedtitle=getCookie(“mysheet”)
if (document.getElementById && selectedtitle!=null) //load user chosen style sheet if there is one stored
setStylesheet(selectedtitle)

演示可见作者网站:http://www.forest53.com

网站统计 Statistics

  • 创建时间: 2005年1月3日 距今5066 天
  • 日志总数: 2461
  • 评论总数: 630
  • 标签总数: 654
  • 链接总数: 273
  • 最后更新: 2018-8-31 17:57:04
  • 您是本站第 14169131 位访客

广告区 Guǎng Gào