弹出模式中的Javascript未运行

时间:2013-05-14 12:09:41

标签: javascript ruby-on-rails ruby ruby-on-rails-3

如何在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 %>

如果您需要更多关于我的代码操作的上下文,请在此处查看上一个问题:Rerun JavaScript on successful ajax call

1 个答案:

答案 0 :(得分:0)

解决!实际上真的很简单......我把它从头部移开并留在体内......

  <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>