不知道,但你的代碼有一些錯別字:
$.cookie Reference here
<script>
$(document).ready(function() { //<-------------no end tag of this
$("#saveForm").click(function() {
$.cookie('myCookie', $("#Website").val(), {
expires: 365,
path: '/'
}); //<---end of $.cookie
}); //<----end of .click
</script>
所以這應該是這樣的:
<script>
$(document).ready(function() {
$("#saveForm").click(function() {
$.cookie('myCookie', $("#Website").val(), {
expires: 365,
path: '/'
}); //<---end of $.cookie
}); //<----end of .click
}); //<----end of doc ready
</script>
,並讀取Cookie,你所要做的只是這正如你所提到的全球餅乾:
<script>
$(document).ready(function() {
$("#Website").val($.cookie('myCookie'));
});
</script>
所以最終的代碼應該是:
<script>
$(document).ready(function() {
$("#saveForm").click(function() {
$.cookie('myCookie', $("#Website").val(), {
expires: 365,
path: '/'
}); //<---end of $.cookie
}); //<----end of .click
$("#Website").val($.cookie('myCookie'));
}); //<----end of doc ready
</script>
來源
2013-11-28 06:47:16
Jai
我不認爲有可能從不同的路徑讀取cookie –
那是什麼'path:'/''在那裏做對象文字?無論如何,只有在設置cookie時才需要指定路徑。 – Barmar
請參閱http://stackoverflow.com/questions/1967963/how-to-access-cookie-values-on-different-paths-of-the-same-domain-using-php –