单击按钮时启动jQuery Modal未加载

Bootstrap jQuery Modal not loading on button click

本文关键字:Modal 加载 jQuery 启动 按钮 单击      更新时间:2023-09-26

我的Rails 4应用程序正在使用通过CDN加载的Twitter Bootstrap,当单击应该加载模态的按钮时,什么都不会发生。如果我试图通过jQuery触发模态,我会得到错误:UnaughtTypeError:undefined不是函数。这是我的代码:

.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');
}); 

您需要在模式代码

中将#new_代理.modal.fade更改为#new_用户.madal.fade

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

相关文章: