自定义背景色:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jquery插件cookie</title>
<script src="js/jquery.min.js"></script>
<script src="js/jquery.cookie.js"></script>
<style>
body{background:yellow;}
.wrap{display:inline-flex;border:10px solid #ffffff;}
.box{width:100px;height:40px;line-height:40px;cursor:pointer;}
.box1{background:red;}
.box2{background:blue;}
.box3{background:blueviolet;}
.box4{background:cornflowerblue;}
</style>
</head>
<body>
<div class="wrap">
<div class="box box1"></div>
<div class="box box2"></div>
<div class="box box3"></div>
<div class="box box4"></div>
</div>
<script>
$(function() {
$(".box").click(function() {
$("body").css("background", $(this).css("background"));
$.cookie(
"background",
$(this).css("background"),
{
expires:60
}
);
});
if ($.cookie("background")) {
$("body").css("background", $.cookie("background"))
};
});
</script>
</body>
</html>
效果图显示: