0
function readCookie(name)
{
  var ca = document.cookie.split(';');
  var nameEQ = name + "=";
  for(var i=0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
  return null;
}

document.ready(function() {

var color = readCookie(go);

if (color != null) {

var gs = document.createElement("link");
gs.type = "text/css";
gs.rel = "stylesheet";
gs.title = "mystyle"
gs.href = "images/audentio/gogreen/green.css";

var rs = document.createElement("link");
rs.type = "text/css";
rs.rel = "stylesheet";
rs.title = "mystyle"
rs.href = "images/audentio/gogreen/red.css";

var bs = document.createElement("link");
bs.type = "text/css";
bs.rel = "stylesheet";
bs.title = "mystyle"
bs.href = "images/audentio/gogreen/blue.css";

if (color == "green"){
    document.getElementsByTagName("head")[0].removeChild(rs);
    document.getElementsByTagName("head")[0].removeChild(bs);
    document.getElementsByTagName("head")[0].appendChild(gs);
}

else if (color == "blue"){
    document.getElementsByTagName("head")[0].removeChild(rs);
    document.getElementsByTagName("head")[0].removeChild(gs);
    document.getElementsByTagName("head")[0].appendChild(bs);
}

else (color == "red"){
    document.getElementsByTagName("head")[0].removeChild(gs);
    document.getElementsByTagName("head")[0].removeChild(bs);
    document.getElementsByTagName("head")[0].appendChild(rs);
}
}
else {
return: false;
}
});

嘿伙计们,我不擅长这些东西,它正在杀死我页面中的所有 jQuery(尽管出于我不会深入的原因,我不想使用 jQuery 来读取 cookie,只创建它)所以有人可以看到错误吗?

现场演示:http ://wedesignthe.net/staff_uploads/eric/ad_development/demo/index.php

4

1 回答 1

0

查找else (color == "red"){并替换为else if(color == "red"){

else (color == "red"){由于您刚刚忘记的此语句而导致的错误if

和改变

else {
    return: false;
}

else {
    return false;
}

remove : between return and false

并更改document.ready(function() {$(document).ready(function() {$(function() {

代替它

if (color == "green"){
    document.getElementsByTagName("head")[0].removeChild(rs);
    document.getElementsByTagName("head")[0].removeChild(bs);
    document.getElementsByTagName("head")[0].appendChild(gs);
}

else if (color == "blue"){
    document.getElementsByTagName("head")[0].removeChild(rs);
    document.getElementsByTagName("head")[0].removeChild(gs);
    document.getElementsByTagName("head")[0].appendChild(bs);
}

else if (color == "red"){
    document.getElementsByTagName("head")[0].removeChild(gs);
    document.getElementsByTagName("head")[0].removeChild(bs);
    document.getElementsByTagName("head")[0].appendChild(rs);
}

var head = document.getElementsByTagName("head")[0];
var links = head.getElementsByTagName("link");
for(var x=0; x<links.length ; x++)
{
   var href = links[x].href;
    if(href.indexOf('/green.css') >0 || href.indexOf('/red.css') >0|| href.indexOf('/blue.css') >0){
      head.removeChild(links[x]);
   }
}

if (color == "green"){
    head.appendChild(gs);
}
else if (color == "blue"){
    head.appendChild(bs);
}

else if (color == "red"){
   head.appendChild(rs);
}
于 2012-10-24T07:41:19.853 回答