/*绑定触发模态框show函数立即执行的回调事件*/ $('#modal').on('show.bs.modal', function (event) { console.log('run..'); //触发模态框的按钮 var button = $(event.relatedTarget) // Button that triggered the modal console.log(button); var recipient = button.data('mydata') // Extract info from data-* attributes var modal = $(this) // modal.find('.modal-title').text('New message to ' + recipient) // modal.find('.modal-body input').val(recipient) console.log(recipient); })
虽然js也可以操纵bootstrap模态框,但看过官网文档后明显提供的方法不足,例如向模态框内传递数据。建议还是使用html来操纵模态框。