你如何看待自举回调模式触发器? [英] How do you think about respective callback for bootstrap modal triggers?

查看:135
本文介绍了你如何看待自举回调模式触发器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

引导模式中,我们知道我们可以绑定触发器的事件,如显示或隐藏显示,显示隐藏隐藏,但此事件绑定仅适用于一般情况。我想要的是具体情况,例如:

On bootstrap modals, we know that we can bind events for triggers like show or hide using show, shown, hide, hidden, but this event binding only works for general case. What I want is 'specific case' such as:

$("#myModal").modal("show", function(e){
    alert("This pops-up after #myModal is shown properly.");
});

或者可能使用词典获取更多选项。

or maybe using dictionaries for more options.

无论如何,我想在这些模态触发器完成之后调用一些函数作为回调。

Anyway, I want to call some functions as callback after these modal triggers are done.

我知道可以有其他的实现,比如使用 setTimeout 等待,直到模态被完全显示或隐藏,或者只是解除绑定回调函数内的事件,所以事件处理程序只工作一次。无论哪种方式,这不是很方便和丑陋。

I do know that there can be alternative implementations, like using setTimeout to wait until the modal is completely shown or hidden, or just unbind the event inside the callback function so the event handler works only for once. Either way, it's not very convenient and ugly.

这个功能是否可行是引导引擎的功能请求?

Can this feature be feasible feature request for bootstrap?

另外,我不太满意,在它的init之后改变模态的属性,我必须通过直接管理 $(#myModal)。data(bs.modal)。 / code>。

Also, I'm not very satisfied that to change modal's property after its init, I have to change it by directly managing $("#myModal").data("bs.modal").options.

再次,我在问特殊情况。我不想为每个 show 显示隐藏或什么。只是针对通过javascript手动触发模态的特定情况。

Again, I'm asking about particular situation. I don't want to make callback function called for every show, shown, hide or what ever. Just for specific situation where the modal is triggered manually via javascript.

这里有一个例子:
让我们说 #myModal #btn-a #btn-b

Here is an example: Let's say that there are #myModal, and #btn-a, #btn-b.

$(document).ready(function(){
    $("#myModal").on("shown.bs.modal", function(e){
        console.log("myModal shown.");
    })
    $("#btn-a").click(function(e){
        $("#myModal").modal("show");
    });
    $("#btn-b").click(function(e){
        // There is no such thing like below. It's just pseudo code.
        $("#myModal").modal("show", function(e2){
            console("myModal shown by b.");
        });
    });
}

然后如果#btn-a 被点击,

myModal shown.

将出现,如果 #btn-a 被点击,

myModal shown.
myModal shown by b.

将出现。

实际上我并没有问问怎么做。我已经做了我想要的我要问的是,这个功能是否是引导功能的可行功能。

Again and again, I'm actually not asking how to make it. I already made what I want. What I'm asking is, will this feature be feasible feature request for bootstrap.

推荐答案

您可以使用显示事件以检测模态何时在屏幕上显示:

You can use shown events to detect when the modal has been made visible on the screen:

$('#myModal').on('shown.bs.modal', function (e) {
    alert("This pops-up after #myModal is shown properly.");
})

您可以在事件部分中查看更多信息模式此处

You can check for more information in the events section of modal here.

这篇关于你如何看待自举回调模式触发器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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