【发布时间】:2012-01-07 00:03:53
【问题描述】:
我有一个使用不同样式表的网站,用户可以使用此代码从中选择活动表:
function setActiveStyleSheet(title) { //title is the title of the link.
var i, a, main; //i is the index pointer, a is a variable used to store the link statement at i
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { //gets all the link elements
if(a.getAttribute("rel").indexOf("style") != -1 // gets the link elements relating to stylesheets
&& a.getAttribute("title")) { //which have the wrong title
a.disabled = true; //disables the wrong stylesheets
if(a.getAttribute("title") == title)
{
a.disabled = false; //if the title of a is equal to the search query, then it is enabled.
}
}
}
}
function changeStyleSheet(sender){
if (sender == "greythumb")
{
setActiveStyleSheet('main');
document.getElementById(sender).className="selected";
document.getElementById('redthumb').className="notSelected";
}
if (sender == "redthumb")
{
setActiveStyleSheet('alternative, red');
document.getElementById(sender).className="selected";
document.getElementById('greythumb').className="notSelected";
}
}
效果很好(目前只有两个)
但是,如果用户选择了红色 CSS,我希望它在用户导航到另一个页面时记住这一点。我记得在某处读到,这是用 cookie 完成的,但我一辈子都找不到它,那么我应该如何实现呢?
干杯
【问题讨论】:
标签: javascript html css cookies