JQuery 使用 cookie

发布于 2024-08-26 01:17:32 字数 785 浏览 3 评论 0原文

在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦屿孤独相伴 2024-09-02 01:17:32

第一个功能应该有所不同。未设置的 cookie 不会产生诸如“true”或“false”之类的值(正如 @rochal 指出的那样,它们是字符串,而不是布尔值),它将为空。另外,如果您的 cookie 正在跟踪是否需要显示启动屏幕,那么它一开始有何价值呢?

function cookieSplash(){
  var cookieSplash = $.cookie('loadSplash');
  if (cookieSplash)
      splash();
  else
      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", "done");
  });
}

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?

function cookieSplash(){
  var cookieSplash = $.cookie('loadSplash');
  if (cookieSplash)
      splash();
  else
      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", "done");
  });
}
夏有森光若流苏 2024-09-02 01:17:32

确保您已包含 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.

落花随流水 2024-09-02 01:17:32

根据 jQuery cookie 演示页面,您设置的 cookie 不正确。使用以下示例语法:

设置:

$.cookie("MySplashCookie", true, { expires: 10 })

读取:

$.cookie("MySplashCookie")

注意:

"true" != true
"false" != false

确保您也保存了正确的类型。

According to demo page for jQuery cookies, you are setting your cookie incorectly. Use this example syntax:

To set:

$.cookie("MySplashCookie", true, { expires: 10 })

To read:

$.cookie("MySplashCookie")

Note:

"true" != true
"false" != false

make sure you are saving correct types too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文