简体   繁体   中英

Cannot set cookie with jQuery Cookie

I'm using jQuery Cookie 1.4.1. Here's my code:

<!DOCTYPE html>
<html lang="en">
  <head>
  </head>
  <body>
    <a href="#" onclick="test()">test</a>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="jquery.cookie.js"></script>
    <script>
      function test() {
        $.cookie('name', 'value');
        console.log($.cookie('name'));
      }
    </script>
  </body>
</html>

The console shows "undefined"

Could anyone help me?

I'm developing on localhost. It seems that Chrome ignores local jQuery cookies:

Why does Chrome ignore local jQuery cookies?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM