[英]How to use cookies to change css <link href=“#”>?
i'm using this script to change the css link href="#" on the targeted document: 我正在使用此脚本来更改目标文档上的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";
}
}
with: 与:
<link id="style1" rel="stylesheet" href="css/style.css" type="text/css" media="screen">
and with button click: 并单击按钮:
<button type="button" onclick="toggle()">Switch</button>
but with this click i need to change the css link href="#" to all my .html documents. 但是单击此按钮,我需要将css链接href =“#”更改为我所有的.html文档。
how to do this with cookies? 如何使用Cookie?
(btw i'm beginner with cookies and js.. so i will need the whole code if can) (顺便说一句,我是Cookie和js的初学者。因此,如果可以,我将需要完整的代码)
Thanks 谢谢
The following article explains exactly what you are looking for - the ability to define alternative style sheets, how to switch between them, and to store that choice in a cookie. 下面的文章准确地解释了您要寻找的内容-定义替代样式表,如何在它们之间进行切换以及将该选择存储在cookie中的功能。
http://alistapart.com/article/alternate http://alistapart.com/article/alternate
Read the article first, but see also the completed example JavaScript file Paul Sowden has written: 首先阅读文章,但另请参阅Paul Sowden编写的完整示例JavaScript文件:
http://d.alistapart.com/alternate/styleswitcher.js http://d.alistapart.com/alternate/styleswitcher.js
i think you need setcookies or some thing like that? 我认为您需要setcookies或类似的东西?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.