在cnbruce''s blog上看到这个即时换STYLE的代码,觉得不错就COPY过来备用.在见的例子就是:一个站点上有多个页面样式提供浏览者选择.同时,在选择了某样式后,再次打开该页面时,将仍然保持该样式.自然会想到了Cookie技术。 程序代码换肤技术<br><!--<BR>function SetCookie(name,value){<BR>var argv=SetCookie.arguments;<BR>var argc=SetCookie.arguments.length;<BR>var expires=(2<argc)?argv[2]:null;<BR>var path=(3<argc)?argv[3]:null;<BR>var domain=(4<argc)?argv[4]:null;<BR>var secure=(5<argc)?argv[5]:false;<BR>document.cookie=name+"="+escape(value)+((expires==null)?"":("; expires="+expires.toGMTString()))+((path==null)?"":("; path="+path))+((domain==null)?"":("; domain="+domain))+((secure==true)?"; secure":"");<BR>}</P> <P>function GetCookie(Name) {<BR>var search = Name + "=";<BR>var returnvalue = "";<BR>if (document.cookie.length > 0) {<br>offset = document.cookie.indexOf(search);<br>if (offset != -1) {<br>offset += search.length;<br>end = document.cookie.indexOf(";", offset);<br>if (end == -1)<br>end = document.cookie.length;<br>returnvalue=unescape(document.cookie.substring(offset,end));<br>}<br>}<br>return returnvalue;<br>}</p> <p>var thisskin;<br>thisskin=GetCookie("nowskin");<br>if(thisskin!="")<br>skin.href=thisskin;<br>else<br>skin.href="css.css";</p> <p>function changecss(url){<br>if(url!=""){<br>skin.href=url;<br>var expdate=new Date();<br>expdate.setTime(expdate.getTime()+(24*60*60*1000*30));<br>//expdate=null;<br>//以下设置COOKIES时间为1年,自己随便设置该时间..<br>SetCookie("nowskin",url,expdate,"/",null,false);<br>}<br>}<br>//--><br> 请选择下面的下拉菜单测试换肤效果 css.csscss1.csscss2.csscss3.css 选择样式单文件<br>var csss=new Array();<br>csss[0]="css.css";<br>csss[1]="css1.css";<br>csss[2]="css2.css";<br>csss[3]="css3.css";<br>var i;<br>for(i=0;i<4;i++)<BR>if(thisskin==csss[i])<BR>document.write("<option value=""+csss[i]+"" selected>"+csss[i]+"样式单文件</option>");<br>else<br>document.write("<option value=""+csss[i]+"">"+csss[i]+"样式单文件</option>");<br>