Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么我的cookie脚本不起作用?_Javascript_Jquery_Cookies - Fatal编程技术网

Javascript 为什么我的cookie脚本不起作用?

Javascript 为什么我的cookie脚本不起作用?,javascript,jquery,cookies,Javascript,Jquery,Cookies,我无法在此网站上找到我的cookie脚本的错误: 如果你去我的网站,你会发现一个隐藏的 它不显示是因为显示:在css中没有,但它应该显示,如果你点击一个按钮,它应该在24小时内隐藏 这是我的剧本: $(document).ready(function() { // If the 'hide cookie is not set we show the message if (!readCookie('hide')) { $('#popupDiv').show(); }

我无法在此网站上找到我的cookie脚本的错误:

如果你去我的网站,你会发现一个隐藏的

它不显示是因为显示:在css中没有,但它应该显示,如果你点击一个按钮,它应该在24小时内隐藏

这是我的剧本:

$(document).ready(function() {

 // If the 'hide cookie is not set we show the message
  if (!readCookie('hide')) {
    $('#popupDiv').show();
  }

  // Add the event that closes the popup and sets the cookie that tells us to
  // not show it again until one day has passed.
  $('#close').click(function() {
    $('#popupDiv').hide();
    createCookie('hide', true, 1)
    return false;
  });

});

// ---
// And some generic cookie logic
// ---
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function eraseCookie(name) {
  createCookie(name,"",-1);
}
这是经过测试的,可以在jQuery打开的默认html文档中使用

我希望有人能帮我:)


向Shane致意你的脚本标记声明中有一个输入错误

它应该是

目前是


我没有看到您的代码中有任何错误。

您所说的“不工作”是什么意思?问题是什么?请在您的问题中包含相关代码。哦,对不起,我忘记我在我的网站上尝试过不同的解决方案,但我现在已经更新了问题。谢谢:)这就解决了!我已经看了几个小时的代码,没有太多的头发,所以谢谢你。“这是多么令人尴尬的错误啊!”沙内基拉很高兴听到这个消息。您可以使用
console.log()
调试代码。
http://jsfiddle.net/FcFW2/1/