当前位置:  开发笔记 > 编程语言 > 正文

Bootstrap模态关闭按钮

如何解决《Bootstrap模态关闭按钮》经验,为你挑选了1个好方法。

我在bootstrap中关闭模式有问题.当我用数据打开模态窗口时(根据触发按钮改变模态内容).这是http://getbootstrap.com/javascript/#modals中的示例




...more buttons...


这没关系,但如果我关闭模态并在其他按钮中打开,当单击发送按钮打印在控制台日志中时,第一个模态和此模态的收件人值.但我只需打印最后一个收件人值.我不明白为什么以前模态的堆栈事件关闭.对于这两个按钮,这是我的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/



1> 小智..:

这是您或您可以说传统方式的旧方式.它还有答案.只需绑定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...

推荐阅读
勤奋的瞌睡猪_715
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有