基础5揭示在javascript中打开的模态无法关闭

Oli*_*liv 5 jquery zurb-foundation

我只是将Foundation 4迁移到Foundation 5.

当我使用jquery脚本打开一个揭示模式时,我在基础5中有一个揭示模态的问题(它在基础4中工作!):显示模态但无法关闭(无论是通过单击X,也不是通过单击在背景上)这是我的代码:

<!doctype html>
<html class="no-js" lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Foundation</title>
    <link rel="stylesheet" href="stylesheets/app.css" />
    <script src="bower_components/modernizr/modernizr.js"></script>
  </head>
  <body>

    <!-- The button -->
    <p><a href="#" class="add2cart button">Reveal Modal</a></p>

    <script src="bower_components/jquery/jquery.js"></script>
    <script src="bower_components/foundation/js/foundation.min.js"></script>
    <script>$(document).foundation()</script>

    <script type="text/javascript">

      $(document).on("click",".add2cart",function(){

          //Create the reveal modal in DOM
          $('body').append('<div id="added2cart" class="reveal-modal small" data-reveal><p>My reveal-modal appears but can\'t be closed !</p><a class="close-reveal-modal">&#215;</a></div>');

          //Open the reveal modal
          $('#added2cart').foundation('reveal', 'open');

      });
    </script>
  </body>
</html>`
Run Code Online (Sandbox Code Playgroud)

知道为什么吗?

提前致谢 !

Log*_*ist 0

我犯了愚蠢的错误。忘记先初始化基础,但看来您确实初始化了它。尝试将 Click JS 代码包装在 $(document).ready(); 中