有这么多关于cookies
和localStorage
(设置,删除...)的文章,但是我不清楚我应该在哪里放置一些代码。如何记住样式更改?
即,我试图改变CSS样式表单击一个按钮,但不能保存下一次加载页面的选择。喜欢的东西:
params.php
if (user clicked on "btntheme") {
$theme = 'green.css';
}else{
$theme = "blue.css";
};
的index.php
<?php include ("params.php");?>
<head>
<link id="link01" rel="stylesheet" href="<?php echo $theme;?>">
</head>
<body>
<div id="btntheme">THEME</div>
</body>
JS
$('#btntheme').click(function(){
$('#link01').attr('href', 'green.css');
});
这改变了风格,但仅适用于当前会话。我怎么能告诉params.php
,以后$theme
是green.css
,而不是blue.css
?
我treid,它的工作原理,但我看到所有的元素首先用'blue.css'(大约一两秒)的样式,然后出现'green.css'。也许这不会发生使用Cookie,而是? – bonaca
这可能是因为您使用PHP来回应主题。为什么不在JS中处理它。PHP在页面后加载并运行。 – TheValyreanGroup