本文介绍了Cookie问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我在这里学习JavaScript并做错了什么,我想要的是做的是将变量的内容存储到cookie中以便它将显示下一个页面打开的时间。我在下面的代码中做了一些错误的事情,因为我没有将nLastBonus的值保存到 ,而是将cookie保存为nLastBonus。 /> 有人能指出我正确的方向吗? //获取cookie var nLastBonus = get_cookie() //饼干是否存在? if(nLastBonus){ //如果没有,那么商店100到nLastBonus // visit_number = 1 nLastBonus = 100 } else { //否则,增加nLastBonus nLastBonus ++ } //设置cookie document.cookie =" last_bonus = nLastBonus;期满= QUOT; + expire_string 解决方案 to document.cookie =" last_bonus =" + escape(nLastBonus)" +; expires =" + expire_string; 通常,你应该转义存储在cookie中的值,以确保它们不包含有意义的字符。它们不包含有意义的字符。在这种情况下,它不是必须的b $ b,因为数字是安全的,但如果nLastBonus是字符串 " foo; expires = now;" (或类似的东西)然后你会得到 麻烦。 / L - Lasse Reichstein Nielsen - lr*@hotpop.com Art D''HTML:< URL: http://www.infimum.dk/HTML/randomArtSplit.html> ''没有判断的信仰只会降低精神神圣。'' " Lasse Reichstein Nielsen" < lr*@hotpop.com> schreef in bericht news:vf ********** @ hotpop.com ... 当您在上面的行中出现错误时,请将其更改为: document.cookie =" last_bonus =" + escape(nLastBonus)+" ; expires =" + expire_string; JW expires =" + expire_string; 当你收到错误时上面一行,将其改为: document.cookie =" last_bonus =" + escape(nLastBonus)+" ; expires =" + expire_string; JW 谢谢那些有效的人! I learning JavaScript and doing something wrong here, what I want todo is store the contents of a variable to a cookie so that it wouldshow the next time the page was opened. I''m doing something wrong inthe code below because instead of saving the value of nLastBonus tothe cookie I''m saving "nLastBonus". Can someone point me in the right direction? // Get the cookievar nLastBonus = get_cookie() // Did the cookie exist?if (nLastBonus) { // If not, then store 100 to nLastBonus// visit_number = 1nLastBonus = 100}else { // Otherwise, increment nLastBonusnLastBonus++} // Set the cookiedocument.cookie="last_bonus=nLastBonus; expires=" + expire_string 解决方案 todocument.cookie="last_bonus="+escape(nLastBonus)"+ ; expires="+expire_string; Generally, you should escape the values stored in cookies to make surethey don''t contain meaningfull characters. In this case, it isn''tnecessary, since numbers are safe, but if nLastBonus was the string"foo;expires=now;" (or something similar that works) then you will gettrouble. /L--Lasse Reichstein Nielsen - lr*@hotpop.comArt D''HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>''Faith without judgement merely degrades the spirit divine.'' And when you get an error on the above line, change it into: document.cookie="last_bonus="+escape(nLastBonus)+" ; expires="+expire_string;JW expires="+expire_string; And when you get an error on the above line, change it into: document.cookie="last_bonus="+escape(nLastBonus)+" ; expires="+expire_string; JWThanks guys that worked! 这篇关于Cookie问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-26 21:34