简体   繁体   English

Bootstrap jQuery Modal在按钮单击时未加载

[英]Bootstrap jQuery Modal not loading on button click

I'm using Twitter Bootstrap loaded via CDN for my Rails 4 app, and when clicking on a button that should load a modal, nothing happens. 我正在为我的Rails 4应用程序使用通过CDN加载的Twitter Bootstrap,并且在单击应该加载模式的按钮时,什么也没有发生。 If I try to trigger the modal via jQuery I get the error: Uncaught TypeError: undefined is not a function. 如果我尝试通过jQuery触发模式,则会收到错误:Uncaught TypeError:undefined不是一个函数。 Here's my code: 这是我的代码:

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

Modal: 模态:

#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: jQuery的:

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

您需要在模态代码中将#new_ agency .modal.fade更改为#new_ user .modal.fade

This was a bootstrap issue. 这是一个引导问题。 When I loaded bootstrap using the gems rather than a CDN, everything worked correctly. 当我使用宝石而不是CDN加载引导程序时,一切正常。 Thanks for your help. 谢谢你的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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