【发布时间】:2012-01-16 09:44:32
【问题描述】:
我想包含一个 20 像素 x 20 像素的潜在背景图像的迷你菜单。 当用户单击其中一个时,主体背景图像将更改,并且选择保存为用户选择。
我曾想过使用滑块,但我不知道如何才能将图像放在 li 中,并能够根据选择更改正文 css。
有什么想法吗?
7 月 4 日快乐
编辑 我正在尝试将 img url 保存在该 cookie 中,但它不起作用,它保存在 cookie 中但它没有检索 cookie 内容
编辑
下面的作品,!!!!!!!但即使我添加背景颜色总是白色
$("html").css("background-color","red");
修复,在网址末尾添加颜色
$("html").css("background", "url('" + imgCookieLink + "') no-repeat fixed center top #343837");
$(document).ready(function() {
$("#BGSelector a").click(function() {
var imgLink = $("img", this).attr("src");
$.cookie("html_img", "" + imgLink + "", { expires: 7 });
var imgCookieLink = $.cookie("html_img");
$("html").css("background", "url('" + imgCookieLink + "')");
});
});
<script type="text/javascript">
$(document).ready(function() {
$("#BGSelector a").click(function() {
var imgLink = $("img", this).attr("src");
$.cookie("html_img", "" + imgLink + "", { path: '/vitamovie', expires: 7 });
var imgCookieLink = $.cookie("html_img");
$("html").css("background", "url('" + imgCookieLink + "') no-repeat fixed center top");
});
});
</script>
<script type="text/javascript">
$(document).ready(function() {
var imgCookieLink = $.cookie("html_img");
$("html").css("background", "url('" + imgCookieLink + "') no-repeat fixed center top");
});
</script>
【问题讨论】:
-
感谢 tvanfosson 的编辑:D
-
我不确定为什么背景颜色不会改变。但我强烈建议你试试 $("body").css("background-color", "#FF0000") 看看会发生什么。
-
$("body").css("background-color", "#FF0000");工作正常,
-
我还有一个问题,在本地这一切都有效,但在网络上它不起作用 cookie 正在改变但正文没有改变vitamovie.com
-
已修复,cookie路径错误:)
标签: jquery css cookies background