COOKIES的内容:
stylesheet=/css/skin2.css
pc_0=/banner/skin2/0.PNG
pc_1=/banner/skin2/1.PNG
pc_2=/banner/skin2/2.PNG
pc_3=/banner/skin2/3.PNG
js的内容如下:function initStyle(){ //初始化样式,如果cookie存在样式,则加载cookie样式,否则加载默认样式  if(/stylesheet=([^;]+)/.test(document.cookie))//判断是否存在cookie.
   getObject("skin").href=unescape(RegExp.$1);     if(/pc_0=([^;]+)/.test(document.cookie))//判断是否存在cookie.
   getObject("pc_0").src=unescape(RegExp.$1);     if(/pc_1=([^;]+)/.test(document.cookie))//判断是否存在cookie.
   getObject("pc_1").src=unescape(RegExp.$1);     if(/pc_2=([^;]+)/.test(document.cookie))//判断是否存在cookie.
   getObject("pc_2").src=unescape(RegExp.$1);     if(/pc_3=([^;]+)/.test(document.cookie))//判断是否存在cookie.
   getObject("pc_3").src=unescape(RegExp.$1);}
initStyle();问题是:
网页中id="skin" 的内容会变
但是id="pc_0",id="pc_1",id="pc_2",id="pc_3"
均没有变化!请问朋友们上面的JS该怎么改!?我的JAVASCRIPT的水平很低。请见谅!

解决方案 »

  1.   

    function getObject(elementId) { //获取指定id的object
     if (document.getElementById) {
      return document.getElementById(elementId);
     } else if (document.all) {
      return document.all[elementId];
     } else if (document.layers) {
      return document.layers[elementId];
     }
    }
      

  2.   

    有点不明白楼主的意思喂  你把图片的路径保存到 cookie 后, 然后每次打开页面的时候再来 initstyle ,在 函数里面进行对页面组件样式的设定啊。
      

  3.   

    没有看明白过来,你从哪里读COOKIES了
    getObject()是如何的???
      

  4.   


    你从什么地方去读取了COOKIES呀?
    你只是判断了有没有,具体的值并没有读出来
      

  5.   

    d="pc_0",id="pc_1",id="pc_2",id="pc_3" 标签属于什么类型的? 图片吗?
    还有那有你这样取cookie的啊
    我给你个cookie操作的例子你看看
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
            <title>Cookie处理函数练习</title>
            <script language="JavaScript" type="text/javascript">
            var $=function(el){
                return (typeof el=='object')?el:document.getElementById(el);
            };        
           var addCookie=function(objName,objValue,objHours){//添加cookie
                var str = objName + "=" + escape(objValue);
                if(objHours > 0){//为0时不设定过期时间,浏览器关闭时cookie自动消失
                    var date = new Date();
                    var ms = objHours*3600*1000;
                    date.setTime(date.getTime() + ms);
                    str += "; expires=" + date.toGMTString();
                }
                document.cookie = str;
                alert("添加cookie成功");
            };        
            var getCookie=function(objName){//获取指定名称的cookie的值
                var arrStr = document.cookie.split("; ");
                for(var i = 0;i < arrStr.length;i ++){
                    var temp = arrStr[i].split("=");
                    if(temp[0] == objName){                
                    return unescape(temp[1]);
                    }
                } 
            };        
            var delCookie=function(name){//为了删除指定名称的cookie,可以将其过期时间设定为一个过去的时间
                var date = new Date();
                date.setTime(date.getTime() - 10000);
                document.cookie = name + "=a; expires=" + date.toGMTString();
                alert("删除成功");
            };        
            var add=function(){//添加Cookie
                var cookie_name = $("cookie_name").value;
                var cookie_value = $("cookie_value").value;
                var cookie_expireHours = $("cookie_expiresHours").value;
                if(cookie_name==""||cookie_value==""){
                  alert("请填写完整Cookie的名称和值");
                  return;
                }
                addCookie(cookie_name,cookie_value,cookie_expireHours);
            };
            var getall=function(){//读取所有保存的cookie字符串
                var str = document.cookie;
                if(str == ""){
                 str = "没有保存任何cookie";
                }
               alert(str);
            };
            var get=function(){//读取单个该名称的cookie
                var cookie_name = $("cookie_name").value;
                var cookie_value = getCookie(cookie_name);
                if(cookie_name ==""){            
                   alert("请填写名称,根据名称进行查找");
                 return;
                }
                if(cookie_value==null){
                  cookie_value="没有该名称的cookie";
                }            
                alert(cookie_value);
            };        
            var del=function(){//删除该名称的cookie
                var cookie_name = $("cookie_name").value;
                if(cookie_name==""){
                  alert("请填写名称,根据名称进行删除");
                  return;
                }            
                delCookie(cookie_name);            
            };
            </script>        
        </head>
        <body>
            <form name="myform">
                <div><label for="cookie_name">Cookie名称:</label><input type="text" name="cookie_name" /></div>
                <div><label for="cookie_value">Cookie &nbsp;值:</lable><input type="text" name="cookie_value" /></div>
                <div><label for="cookie_expireHours">过期时间(小时):</lable><input type="text" name="cookie_expiresHours" /></div><hr/>
                <div>
                    <input type="button" value="添加该cookie" onclick="add()" />
                    <input type="button" value="读取所有cookie" onclick="getall()" />
                    <input type="button" value="读取该名称cookie的值" onclick="get()" />
                    <input type="button" value="删除该名称cookie" onclick="del()" />
                </div>
            </form>
            <hr />
        </body>
    </html>
      

  6.   

    function getObject(elementId) { //获取指定id的object
     if (document.getElementById) {
      return document.getElementById(elementId);
     } else if (document.all) {
      return document.all[elementId];
     } else if (document.layers) {
      return document.layers[elementId];
     }
    }
    function changeStyle(id){//切换样式
     var stylesheet=getObject("skin").href="/css/skin"+id+".css";
     var pc_0=getObject("pc_0").src="/banner/skin"+id+"/0.PNG";
     var pc_1=getObject("pc_1").src="/banner/skin"+id+"/1.PNG";
     var pc_2=getObject("pc_2").src="/banner/skin"+id+"/2.PNG";
     var pc_3=getObject("pc_3").src="/banner/skin"+id+"/3.PNG";
     document.cookie="stylesheet="+escape(stylesheet);//写入Cookie
     document.cookie="pc_0="+escape(pc_0);
     document.cookie="pc_1="+escape(pc_1);
     document.cookie="pc_2="+escape(pc_2);
     document.cookie="pc_3="+escape(pc_3); //alert(document.cookie);
     //alert(stylesheet);
    }
    function initStyle(){ //初始化样式,如果cookie存在样式,则加载cookie样式,否则加载默认样式
      if(/stylesheet=([^;]+)/.test(document.cookie))//判断是否存在cookie.
       getObject("skin").href=unescape(RegExp.$1);
         if(/pc_0=([^;]+)/.test(document.cookie))//判断是否存在cookie.}
    initStyle();
    这是我的SKIN.JS的内容
    这是网上一段切换皮肤的JS,
    点切换的时候JS就会换了网站的CSS样式表!网站有个id="skin" 的样式表连接就会根据所传递来的ID变化SKIN*.CSS。
    然后把该皮肤的样式表保存在COOKIES,就算刷新了页面,还是客户选择的皮肤。
    后来因为我需要每个个风格有每个风格的BANNER条。所以就要换掉。一个页面有四个banner条幻灯效果切换的。
    就是id="pc_0"
        id="pc_1"
        id="pc_2"
        id="pc_3"
    后来自己改了一下JS的内容。切换皮肤的时候能自动替换掉图片。但是刷新后,
    还是回到默认的四个默认的图片
    pc_0=/banner/skin1/0.PNG
    pc_1=/banner/skin1/1.PNG
    pc_2=/banner/skin1/2.PNG
    pc_3=/banner/skin1/3.PNG
    而不能会显示客户选择SKIN2皮肤的时候的BANNER的四个图片。
    后来检查,COOKIES里面是有的:
    pc_0=/banner/skin2/0.PNG
    pc_1=/banner/skin2/1.PNG
    pc_2=/banner/skin2/2.PNG
    pc_3=/banner/skin2/3.PNG我的意思就是想把COOKIES里面的PC_0,PC_1,PC_2,PC_3的内容。
    在打开的页面的时候,判断一下是否为空,如果不为空分别赋予页面上id="pc_0",id="pc_1",id="pc_2",id="pc_3"的图片上去