簡體   English   中英

如何使用Cookie更改CSS <link href=“#”> ?

[英]How to use cookies to change css <link href=“#”>?

我正在使用此腳本來更改目標文檔上的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的初學者。因此,如果可以,我將需要完整的代碼)

謝謝

下面的文章准確地解釋了您要尋找的內容-定義替代樣式表,如何在它們之間進行切換以及將該選擇存儲在cookie中的功能。

http://alistapart.com/article/alternate

首先閱讀文章,但另請參閱Paul Sowden編寫的完整示例JavaScript文件:

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

我認為您需要setcookies或類似的東西?

“; echo” Value is:“。$ _COOKIE [$ cookie_name];}?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM