【问题标题】:Bootstrap jQuery Modal not loading on button clickBootstrap jQuery Modal 未在按钮单击时加载
【发布时间】:2014-12-05 23:52:24
【问题描述】:

我正在为我的 Rails 4 应用程序使用通过 CDN 加载的 Twitter Bootstrap,当单击应该加载模式的按钮时,没有任何反应。如果我尝试通过 jQuery 触发模式,我会收到错误:Uncaught TypeError: undefined is not a function。这是我的代码:

.container
.row
    .col-sm-12
        %h1 Manage Team
        .pull-right
            %a.btn.btn-success#addUserBtn{ data: { toggle: :modal, target: '#new_user' } }
                Add

模态:

#new_user.modal.fade
.modal-dialog
    .modal-content
        .modal-header
            %button.close{ type: :button, 'data-dismiss' => 'modal', 'aria-hidden' => 'true' }
                ×
            %h4.modal-title
                New Agency
        = form_for Agency.new( facilitator_id: current_user.id ) do |f|
            .modal-body
                .form-group
                    = f.label :name
                    = f.text_field :name, class: 'form-control'
                .form-group
                    = f.label :facilitator_id
                    = f.collection_select :facilitator_id, User.admin, :id, :name, {}, class: 'form-control'

            .modal-footer
                %button.btn.btn-default{ type: :button, 'data-dismiss' => 'modal' }
                    Close
                = f.submit 'Create', class: 'btn btn-primary'

jQuery:

$('#addUserBtn').on('click', function() {
    console.log('test');
    $('#new_user').modal('toggle');
}); 

【问题讨论】:

    标签: javascript jquery ruby-on-rails twitter-bootstrap bootstrap-modal


    【解决方案1】:

    您需要在模态代码中将 #new_agency.modal.fade 更改为 #new_user.modal.fade

    【讨论】:

    • 好收获。改变了这一点,但仍然没有运气。
    【解决方案2】:

    这是一个引导问题。当我使用 gems 而不是 CDN 加载引导程序时,一切正常。感谢您的帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-26
      • 2012-08-31
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多