Posted in Javascript onNovember 04, 2013
<!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>
利用cookie记住背景颜色示例代码
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@