jquery - bootstrap3模态中的回调函数

标签 jquery callback twitter-bootstrap-3

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

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

但是在 bootstrap 3 模态中,我通过脚本触发模态,并且根据我对他们网站中的解释的理解,我这样做了。

$('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的模态中调用回调函数?

最佳答案

对于 Bootstrap 3,事件现在已命名,因此模式的 show 事件将为 show.bs.modal...

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

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

关于jquery - bootstrap3模态中的回调函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19676392/

相关文章:

javascript - 单击复选框后获取每个 tr 的 td 值

jquery - 如何让 jquery ui 标签工作?

javascript - 正则表达式回调函数只执行一次

javascript - 如何在Bootstrap中为*独立*几个进度条部分设置动画?

javascript - 如何沿页面中心垂直堆叠多个 html/css 按钮?

javascript - 如何更新javascript中setInterval函数的持续时间?

javascript - 如何实现向 NaCl(Chrome Native Client)发送消息后的回调?

ios - 如何避免我没有编写的 swift 函数的回调 hell ?

twitter-bootstrap-3 - Bootstrap 日期选择器切换禁用

html - 无法将 div 内容定位到页面中心