我在bootstrap中关闭模式有问题.当我用数据打开模态窗口时(根据触发按钮改变模态内容).这是http://getbootstrap.com/javascript/#modals中的示例
...more buttons...New message
这没关系,但如果我关闭模态并在其他按钮中打开,当单击发送按钮打印在控制台日志中时,第一个模态和此模态的收件人值.但我只需打印最后一个收件人值.我不明白为什么以前模态的堆栈事件关闭.对于这两个按钮,这是我的jquery代码:
$('#exampleModal').on('show.bs.modal', function (event) { var button = $(event.relatedTarget) // Button that triggered the modal var recipient = button.data('whatever') // Extract info from data-* attributes // If necessary, you could initiate an AJAX request here (and then do the updating in a callback). // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead. var modal = $(this) modal.find('.modal-title').text('New message to ' + recipient) modal.find('.modal-body input').val(recipient) $("#btnsend").one("click", function(){ console.log('Pinchado') console.log(recipient) }) $("#btnclose").one("click", function(){ console.log('Cerrando...') }) $('#exampleModal').on('hidden.bs.modal', function (e) { console.log('Cerrada'); }) })
非常感谢你,我希望有人能帮助我. https://jsfiddle.net/DTcHh/28480/
这是您或您可以说传统方式的旧方式.它还有答案.只需绑定hide并单击show event bind之外的eventd.
$('#exampleModal').on('show.bs.modal', function(event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var recipient = button.data('whatever') // Extract info from data-* attributes
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
var modal = $(this)
modal.find('.modal-title').text('New message to ' + recipient)
modal.find('.modal-body input').val(recipient)
})
$("#btnsend").on("click", function() {
console.log('Pinchado')
console.log(recipient)
})
$("#btnclose").on("click", function() {
console.log('Cerrando...')
})
$('#exampleModal').on('hidden.bs.modal', function(e) {
console.log('Cerrada');
})
...more buttons...
New message