bootstrap3模态回调函数 [英] Call back function in modal of bootstrap3

查看:27
本文介绍了bootstrap3模态回调函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对在 bootstrap3 的 javascript 模式中触发回调函数有点困惑.在普通的 jquery.post 中,你可以这样做,

Im a little bit confuse about firing a call back function in javascript modal of bootstrap3. In normal jquery.post you can do it like,

$.post('path', { something: something }, function(data) { 
  console.log(data);
});

但是在 bootstrap 3 modal 中,我通过脚本触发了模态,我这样做是基于我对他们网站上的解释的理解.

But in bootstrap 3 modal I fires the modal through script and I do it like this base on how I understand the explanation in their website.

$('selector').modal('show', function() { 
  //here comes the problem, I have a button in the modal in the html, my code
  //if the button was clicked inside this modal is..

  $('#myButton').on('click', function() { 
     console.log("this is a try");
  });
});

但遗憾的是,如果我单击按钮,什么也没有发生,控制台也没有记录任何内容.如何在 bootstrap 3 的模态中调用回调函数?

But sad to say if I click the button, nothing is happening, nothing was logged in the console. How do I call a callback function in a modal of bootstrap 3?

推荐答案

对于 Bootstrap 3,事件现在是命名空间的,因此模态的 show 事件将是 show.bs.模态...

For Bootstrap 3, the events are now namespaced, so the show event for the modal would be show.bs.modal...

$('#myModal').on('show.bs.modal', function (e) {
    alert('modal show');
});

演示:http://bootply.com/90952

这篇关于bootstrap3模态回调函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆