jQuery通过cookie自定义背景
我正在为我的网站制作背景更改脚本。除了应该存储所需值的 cookie 之外,一切正常。我正在使用 jQuery 1.3。 IE 8 说:“第 47 行 char 118567432 上的对象不支持此属性或方法”!?任何帮助将不胜感激。没有 cookie 的工作示例:
function images(which,image) {
if (which == 't1')image = images[0];
else if (which == 't2')image = images[1];//and etc...
}
$('html').css("background-image", image);
有 cookie 的示例(不起作用):
function images(which,image) {
if (which == 't1')image = images[0];
{$.cookie("html_img", "" + image + "", { expires: 7 });
imgCookie = $.cookie("html_img");}
else if (which == 't2')image = images[1];
{$.cookie("html_img", "" + image + "", { expires: 7 });
imgCookie = $.cookie("html_img");}
}
$('html').css("background-image", imgCookie);
I'm making background changing script for my site. Everything works fine except the cookie which should store the required value. I'm using jQuery 1.3. IE 8 says: 'object doesn't support this property or method on line 47 char 118567432'!? Any help will be greatly appreciated. Working example without cookie:
function images(which,image) {
if (which == 't1')image = images[0];
else if (which == 't2')image = images[1];//and etc...
}
$('html').css("background-image", image);
Example with cookie (not working):
function images(which,image) {
if (which == 't1')image = images[0];
{$.cookie("html_img", "" + image + "", { expires: 7 });
imgCookie = $.cookie("html_img");}
else if (which == 't2')image = images[1];
{$.cookie("html_img", "" + image + "", { expires: 7 });
imgCookie = $.cookie("html_img");}
}
$('html').css("background-image", imgCookie);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已将您的代码转换为更高效、语法上有效的 JavaScript 代码。
I've converted your code to a more efficient, and syntactically valid JavaScript code.
可能是你的“cookie插件”脚本没有正确导入?您能否提供有关您收到的错误的更多详细信息。使用 Firebug for Firefox 或 Chrome 开发工具来获得更好的错误跟踪。
May be your "cookie plugin" script is not imported correctly? Can you give more details on the error you get. Use Firebug for Firefox or Chrome Dev tools to get a better error trace.