【问题标题】:How to use cookies to change css <link href="#">?如何使用cookies改变css <link href="#">?
【发布时间】:2013-11-20 14:15:15
【问题描述】:

我正在使用此脚本更改目标文档上的 css 链接 href="#":

<script type='text/javascript'>
function toggle() {
    var el = document.getElementById("style1");
    if (el.href.match("css/style.css")) {
        el.href = "css/style-b.css";    
    }
    else {
        el.href = "css/style.css";  
    }
}

与:

<link id="style1" rel="stylesheet" href="css/style.css" type="text/css" media="screen">

点击按钮:

<button type="button" onclick="toggle()">Switch</button>

但是通过单击,我需要将 css 链接 href="#" 更改为我的所有 .html 文档。

如何使用 cookie 做到这一点?

(顺便说一句,我是 cookie 和 js 的初学者。如果可以的话,我将需要整个代码)

谢谢

【问题讨论】:

    标签: javascript html css cookies href


    【解决方案1】:

    以下文章准确解释了您正在寻找的内容 - 定义替代样式表的能力、如何在它们之间切换以及将该选择存储在 cookie 中。

    http://alistapart.com/article/alternate

    请先阅读文章,但也请参阅 Paul Sowden 编写的完整示例 JavaScript 文件:

    http://d.alistapart.com/alternate/styleswitcher.js

    【讨论】:

      【解决方案2】:

      我认为您需要 setcookies 或类似的东西?

      "; 回声“价值是:”。 $_COOKIE[$cookie_name]; } ?>

      【讨论】:

        猜你喜欢
        • 2020-11-21
        • 1970-01-01
        • 2012-09-23
        • 1970-01-01
        • 1970-01-01
        • 2010-11-30
        • 2015-10-16
        • 1970-01-01
        • 2021-03-08
        相关资源
        最近更新 更多