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

时间:2014-11-10 08:58:03

标签: javascript jquery cookies

我无法找到我在此网站上的Cookie脚本有什么问题:     http://lampen.identitest.dk/

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

<div id="popupDiv">

它没有显示因为显示: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);
}

我在

上找到了cookie脚本
http://jsfiddle.net/FcFW2/1/

这是经过测试的,并且在jQuery on的默认html文档中工作。

我希望有人可以帮助我:)

致敬Shane

1 个答案:

答案 0 :(得分:0)

您的脚本标记声明中存在拼写错误。

应为<script type="text/javascript">

目前它是<script type="type/javascript">

我在代码中看不到任何错误。

相关问题