. 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="Scripts/jquery-1.10.2.min.js"></script>
<script src="Scripts/jquery.cookie.js" type="text/javascript"></script>
<style type="text/css">
#p1{ background-color:Red ; width:40px; border:solid 1px yellow ; margin:5px; float:left}
#p2{background-color:Yellow ;width:40px; border:solid 1px red; margin:5px; float:left}
#p3{background-color:Blue;width:40px; border:solid 1px yellow; margin:5px; float:left}
</style>
<script type="text/javascript">
$(function () {
if ($.cookie("bgcolor")) {
$("body").css("background-color", $.cookie("bgcolor"));
}
$("p").click(function () {
$("body").css("background-color", $(this).css("background-color"));
$.cookie("bgcolor", $("body").css("background-color"), { expires: 7 });
})
})
</script>
</head>
<body>
<p id="p1">紅色</p><p id="p2">黃色</p><p id="p3">藍色</p>
</body>
</html>