<!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>cookie插件</title> ? ? ? ?<link href="style.css" rel="stylesheet" type="text/css" /> ? ? ? ?<script type="text/javascript" src="http://idcbgp.cn/data/jquery-1.8.2.min.js"></script> ? ? ? ?<script src="http://idcbgp.cn/data/jquery.cookie.js" type="text/javascript"></script> ? ?</head> ? ? ? ?<body> ? ? ? ?<div id="divtest"> ? ? ? ? ? ?<div class="title"> ? ? ? ? ? ? ? ?<span class="fl">cookie插件</span> ? ? ? ? ? ? ? ?<span class="fr"> ? ? ? ? ? ? ? ? ? ?<input id="btnSet" type="button" value="設(shè)置" /> ? ? ? ? ? ? ? ?</span> ? ? ? ? ? ?</div> ? ? ? ? ? ?<div class="content"> ? ? ? ? ? ? ? ?<span class="fl">郵箱:</span><br /> ? ? ? ? ? ? ? ?<input id="email" name="email" type="text" /><br /> ? ? ? ? ? ? ? ?<input id="chksave" type="checkbox" />是否保存郵箱 ? ? ? ? ? ?</div> ? ? ? ?</div> ? ? ? ? ? ? ? ?<script type="text/javascript"> ? ? ? ? ? ?$(function () { ? ? ? ? ? ? ? ?if ($.cookie("email")) { ? ? ? ? ? ? ? ? ? ? ?$("#email").val($.cookie("email")); ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ?if($.cookie("che")){ ? ? ? ? ? ? ? ? ? ?$("#chksave").attr("checked",true); ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ?$("#btnSet").bind("click", function () { ? ? ? ? ? ? ? ? ? ?if ($("#chksave").is(":checked")) { ? ? ? ? ? ? ? ? ? ? ? ?$.cookie("email",$("#email").val(), { ? ? ? ? ? ? ? ? ? ? ? ? ? ?path: "/", expires: ?7 ? ? ? ? ? ? ? ? ? ? ? ?}), ? ? ? ? ? ? ? ? ? ? ? ?$.cookie("che",true, { ? ? ? ? ? ? ? ? ? ? ? ? ? ?path: "/", expires: ?7 ? ? ? ? ? ? ? ? ? ? ? ?}) ? ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?else { ? ? ? ? ? ? ? ? ? ? ? ? ?$.cookie("email",null, { ? ? ? ? ? ? ? ? ? ? ? ? ? ?path: "/" ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}), ? ? ? ? ? ? ? ? ? ? ? ?$.cookie("che",null, { ? ? ? ? ? ? ? ? ? ? ? ? ? ?path: "/" ? ? ? ? ? ? ? ? ? ? ? ?}) ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ?}); ? ? ? ? ? ?}); ? ? ? ?</script> ? ?</body></html>
2 回答

李曉健
TA貢獻(xiàn)1036條經(jīng)驗(yàn) 獲得超461個(gè)贊
cookie是需要種到域名或ip下面的。所以你本地需要有一個(gè)web服務(wù)。訪問時(shí)不要用localhost來訪問,用ip或127.0.0.1?

喵嗚_0001
TA貢獻(xiàn)4條經(jīng)驗(yàn) 獲得超2個(gè)贊
先回答樓主的問題,cookie和服務(wù)器并無關(guān)系。cookie的機(jī)制受很多因素影響,其中有瀏覽器安全設(shè)置,建議你先檢查一下瀏覽器支不支持cookie存儲(chǔ),我記得mac就不行,課程里的試驗(yàn),我在自己電腦上試過,是沒有問題的。
另外,樓主你引用的不是cookie插件啊喂【汗】
點(diǎn)擊展開后面6條
- 2 回答
- 0 關(guān)注
- 1467 瀏覽
添加回答
舉報(bào)
0/150
提交
取消