Javascript代码Cookie保留/保留替代Css
Javascript code Cookie to retain/keep alternative Css
能帮忙吗我创建了一个网站,但需要知道如何让用户选择他们想要使用的css。我想我需要使用cookie,但我不是100%确定
这是我的索引页
<html>
<head>
<title>Internet Privacy</title>
<link rel="stylesheet" type="text/css" href="styles/styles.css" title="Standard">
<link rel="alternate stylesheet" type="text/css" href="styles/AStyles.css" title="wacky" />
<script type="text/javascript">
function changeCSS(cssFile, cssLinkIndex) {
var oldlink = document.getElementsByTagName("link").item(cssLinkIndex);
var newlink = document.createElement("link");
newlink.setAttribute("rel", "stylesheet");
newlink.setAttribute("type", "text/css");
newlink.setAttribute("href", cssFile);
document.getElementsByTagName("head").item(0).replaceChild(newlink, oldlink);
}
document.cookie="CSS="
</script>
</head>
<body>
<div class="main_wrapper">
<div class="header_wrapper">
<!-- This the Logo and Banner Links-->
<a href="index.php"><img id="logo" src="images/Logo.jpg" height="200" width="350"></a>
<a href="http://www.wlv.ac.uk"><img id="banner" src="images/wlvLogo.gif" height="200" width="650">
</div>
<div class="menubar">
<ul id="menu">
<!-- This is the Menubar that contains links to the various other pages-->
<li><a href="index.html">Home</a></li>
<li><a href="about.html">Privacy Laws</a></li>
<li><a href="procon.html">Pros and Cons</a></li>
<li><a href="wfa.html">Fights for Privacy</a></li>
<li><a href="aboutme.html">About Me</a></li>
</ul>
</div>
<div class="content_wrapper">
<!-- This is the Sidebar -->
<div class="text">
<h2>I have created this website for my first assignment.<br>This website is about how private the internet and how companies collect data, and how the data is used.</h2><br>
<img id="indeximg" src="images/privacy.jpg" height="200" width="500">
<br><p>Change Css Here <br>
<a href="#" onclick="changeCSS('styles/styles.css', 0);">Style 1</a> <br>
<a href="#" onclick="changeCSS('styles/AStyles.css', 0);">Style 2</a>
</div>
</div>
<div id="footer"><!-- This is the footer and it will be at the bottom of the page -->
<br><p>The website was created by Vincent Priestley at The University of Wolverhampton 2015</p>
</div>
</div>
</body>
如果有人能帮忙,我将不胜感激
提前谢谢你Vinni
伙计,我不太清楚你的要求是什么,但一般来说,如果你想存储用户的信息,它不应该在前端完成,我的意思是cookie,本地存储…
保存用户的信息,你需要数据库(甚至文件)和服务器端语言来做它,像php+my-sql, asp.mvc+sql…
使用cookie或任何其他前端技术是不好的,无论如何…
相关文章:
- 禁用滚动,但保留滚动条CSS
- 如何在javascript中进行CSS单元计算并保留CSS单元
- 应该很简单:当转到另一个页面时,如何在基本javascript/css/html页面上保留数据
- 使用 javascript 动态更改文本时保留 CSS
- 如何在不使用 CSS 的情况下在动态添加的 javascript DOM 元素中保留空格
- CSS:当 image1 动画不合适时,一组图像会移动,而它们应该保留在原处
- 如何从 css 动画关键帧获取图像以在完成后保留在页面上
- Javascript“对象”不保留css值
- 在悬停时保留和添加新的转换 (CSS/LESS)
- 在保留CSS的同时更改innerHTMl
- 当代码包含保留字时,设置代码的CSS
- 是否可以使用JavaScript转储DOM并保留CSS效果和布局
- 如何保留页面'阻止CSS影响加载html文档的iframe
- SVG到PNG保留CSS使用javascript
- Javascript代码Cookie保留/保留替代Css
- Jquery不保留CSS样式
- 将HTML加载到DIV中,但保留CSS,JS包括
- 对列表进行排序,但保留CSS标记
- 当Flash层放置在元素上时,保留CSS动画
- 用Javascript填充HTML表并保留CSS样式