隨機載入CSS樣式的JS效果實際上很好實現
隨機載入CSS樣式的JS效果實際上很好實現
var Init = {
//樣式表文件目錄路徑
baseSkinUrl : "/blog/css/skin/"
//樣式表文件名稱列表
styles : ["default"
//樣式cookie的key值
cookieKey : "css
//定義方法
getRandomNum : function(min
return min + Math
}
//定義方法
getCookie : function(name) {
var arr = document
if (arr != null) {
return unescape(arr[
}
return null;
}
//定義方法
setCookie : function(sName
var sCookie = sName + "=" + encodeURIComponent(sValue);
if (objHours) {
var date = new Date();
var ms = objHours *
date
sCookie += ";expires=" + date
}
if (sPath) {
sCookie += ";path=" + sPath;
}
if (sDomain) {
sCookie += ";domain=" + sDomain;
}
if (bSecure) {
sCookie += ";secure";
}
document
}
//定義方法
loadCSS : function(){
var length = this
random = this
cookieStyle = this
currentStyle = "default";
//如果當前隨機取到的樣式與cookie中樣式相同
while(this
{
random = this
}
currentStyle = this
//將新樣式存入cookie
this
//若樣式名稱不為"default"默認樣式
if(currentStyle != "default")
{
document
href="
}
}
}
Init
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20634.html