JQuery 使用 cookie
在我的 js 文件中,我希望能够在正在开发的新空气应用程序中加载“启动屏幕”。目前,当我调用启动屏幕时,它可以正常打开和关闭,但是当我设置 cookie 时,它根本不运行。请帮助...
cookieSplash();
function cookieSplash(){
var cookieSplash = $.cookie('loadSplash');
if (cookieSplash == "true") {
splash();
};
if (cookieSplash == "false") {
loadApplication();
};
}
function splash(){
$("#viewport").append('<div id="splash"><img id="splash-close" src="/images/splash-logo.png" alt="click to close"></div>');
$("#splash").click(function() {
// Act on the event
$("#splash").fadeOut("slow");
$("#jettison").fadeIn("fast");
$.cookie("loadSplash", "false");
});
}
function loadApplication(){
$("#jettison").fadeIn("fast");
}
请帮助我
in my js file i want to be able to load a "splash screen" in a new air app im developing. At present when i call the splash screen it opens and closes fine, but its when i make it set a cookie it doesnt run at all. Please help...
cookieSplash();
function cookieSplash(){
var cookieSplash = $.cookie('loadSplash');
if (cookieSplash == "true") {
splash();
};
if (cookieSplash == "false") {
loadApplication();
};
}
function splash(){
$("#viewport").append('<div id="splash"><img id="splash-close" src="/images/splash-logo.png" alt="click to close"></div>');
$("#splash").click(function() {
// Act on the event
$("#splash").fadeOut("slow");
$("#jettison").fadeIn("fast");
$.cookie("loadSplash", "false");
});
}
function loadApplication(){
$("#jettison").fadeIn("fast");
}
Please help me out
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
第一个功能应该有所不同。未设置的 cookie 不会产生诸如“true”或“false”之类的值(正如 @rochal 指出的那样,它们是字符串,而不是布尔值),它将为空。另外,如果您的 cookie 正在跟踪是否需要显示启动屏幕,那么它一开始有何价值呢?
That first function should be different. An unset cookie won't result in values like "true" or "false" (which as @rochal noted are strings, not booleans), it'll be null. Also, if your cookie is keeping track of whether or not the splash screen needs to be shown, how will it have any value in it at all at first?
确保您已包含
jquery_cookie.js
。如果有,那么我建议使用 Firefox/Firebug 并检查控制台是否有 JavaScript 错误。Make sure you've included
jquery_cookie.js
. If you have, then I suggest using Firefox/Firebug and check the console for javascript errors.根据 jQuery cookie 演示页面,您设置的 cookie 不正确。使用以下示例语法:
设置:
读取:
注意:
确保您也保存了正确的类型。
According to demo page for jQuery cookies, you are setting your cookie incorectly. Use this example syntax:
To set:
To read:
Note:
make sure you are saving correct types too.