弹出式模态中的Javascript未运行

Javascript within pop-up modal not running

本文关键字:运行 Javascript 模态 弹出式      更新时间:2023-09-26

如何让下面的代码在JavaScript弹出式模态框的负载内运行?我在用facebox。http://defunkt.io/facebox/

<% content_for :javascript do %>
  <script type='text/javascript'>
    $(function () {
        function InitializeEvents() {
            /* new category */
            $('#new_admin_category').on('ajax:success', function (event, data, status, xhr) {
                $("#dashboard_categories").html(data.html);
                InitializeEvents();
            });
            /* delete category */
            $('a[data-remote]').on('ajax:success', function (event, data, status, xhr) {
                $("#dashboard_categories").html(data.html);
                InitializeEvents();
            });
        }
        InitializeEvents();
    })();
  </script>
<% end %>

如果你需要更多的上下文我的代码在做什么,请参阅前面的问题在这里:重新运行JavaScript成功的ajax调用

解决!其实很简单……我把它从头部取出,留在身体里…

  <script type='text/javascript'>
    $(function () {
        function InitializeEvents() {
            /* new category */
            $('#new_admin_category').on('ajax:success', function (event, data, status, xhr) {
                $("#dashboard_categories").html(data.html);
                InitializeEvents();
            });
            /* delete category */
            $('a[data-remote]').on('ajax:success', function (event, data, status, xhr) {
                $("#dashboard_categories").html(data.html);
                InitializeEvents();
            });
        }
        InitializeEvents();
    })();
  </script>