Jquery Cookie和SlideToggle或Hide的问题

时间:2017-06-29 09:43:31

标签: jquery cookies slidetoggle

我在stackoverflow上访问过很多关于Jquery cookies的页面,我想我已经找到了一个合适的解决方案来解决我想做的事情。但我得到这个错误,我无法弄清楚。希望你们能帮助我。

index.html:45 Uncaught ReferenceError: signupcookie is not defined
    at HTMLDivElement.onclick

代码:

<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script>

<!--Container for newsletter signup-->
<div id="signupToggled">


<div class="signupToggledContent">

  <h4>
    Tilmeld dig vores nyhedsbrev og vind et gavekort på 500 kroner.
  </h4>
  <p>
    Hver måned trækker vi lod om et gavekort på 500kr., blandt alle læsere af vores nyhedsbrev.
  </p>

</div>


<div id="mc_embed_signup">
  <form action="//mopra.us1.list-manage.com/subscribe/post?u=6ee93f66b0feabf294d03411a&amp;id=0888632a82"
  method="post" id="mc-embedded-subscribe-form"
  name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
      <div id="mc_embed_signup_scroll">
        <div class="group">
            <input type="email" value="" name="EMAIL" class="email" id="mce-EMAIL" required>
          <label>Email</label>
        </div>
        <input type="submit" value="Tilmeld" name="subscribe" id="mc-embedded-subscribe" class="button">
      <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
      <div style="position: absolute; left: -5000px;" aria-hidden="true">
        <input type="text" name="b_6ee93f66b0feabf294d03411a_0888632a82" tabindex="-1" value=""></div>
      </div>
  </form>
</div>

</div>

<!--HERE THE COOKIE WILL BE SET - Also it is here where the error comes up-->
<div id="signupToggle" value="Vind et gavekort!" onclick="signupcookie()"></div>



<script type="text/javascript">


$( document ).ready(function() {

  function signupcookie(){

     days=30;
     myDate = new Date();
     myDate.setTime(myDate.getTime()+(days*24*60*60*1000));

     document.cookie = 'signupcookie=Accepted; expires=' + myDate.toGMTString();

  }

  function CheckCookies(){
      if ($.cookie("signupcookie") === "Accepted")
      {
          $("#signupToggled").slideToggle();
      }
  }


  $( "#signupToggle" ).click(function(e) { 
    $( "#signupToggled" ).slideToggle( "fast", function() {  });
    $(this).toggleClass('is-active'); 
  });


});

</script>
</body>
</html>

0 个答案:

没有答案