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. If I try to trigger the modal via jQuery I get the error: Uncaught TypeError: undefined is not a function. 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:
$('#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. Thanks for your help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.