我在理解 Bootstraps Modal Callbacks时遇到问题。
以下代码的“ .on('show',function(){}) ”部分未触发。不知道为什么。请指教。此外,欢迎任何/所有代码优化提示。
的HTML
<p><a class="bsModal" href="#" title="Bootstrap Modal">testing modal</a></p>
jQuery
// Dynamically calling Bootstrap Modal
$('.bsModal').click(function(){
var bsModalWindow = '<div class="modal" id="myModal">';
bsModalWindow += '<div class="modal-header">';
bsModalWindow += '<button type="button" class="close" data-dismiss="modal">×</button>';
bsModalWindow += '<h3>Modal header</h3>';
bsModalWindow += '</div>';
bsModalWindow += '<div class="modal-body">';
bsModalWindow += '<p>This is an example of the Bootstrap jQuery Plugin: Modal.</p>';
bsModalWindow += '</div>';
bsModalWindow += '<div class="modal-footer">';
bsModalWindow += '<a href="#" class="btn" data-dismiss="modal">Close</a>';
bsModalWindow += '<a href="#" class="btn btn-primary">Save changes</a>';
bsModalWindow += '</div>';
bsModalWindow += '</div>';
$(bsModalWindow).modal()
.on('show', function() {
console.log('Modal will be shown');
})
.on('shown', function() {
console.log('Modal was shown');
})
.on('hide', function() {
console.log('Modal will be hidden');
})
.on('hidden', function() {
console.log('Modal is hidden');
})
.show({
backdrop: true,
keyboard:true
});
});