2

我对 Internet Explorer 中的引导模式事件有疑问。

我正在构建的网站中有几个模式,每个模式都有许多链接,一旦隐藏模式,点击这些链接就会做不同的事情。问题是这些事件不会触发,除非该模式在 Internet Explorer 中至少打开和关闭过一次。

一些代码,这将在我的模式中的每个按钮上重复,关闭时会发生不同的事件:

$('#my-btn').on('click', function() {
    $("#my-modal").modal('hide').on('hidden', function(){
        alert("This wont fire in IE first time around");
    });
});

我的解决方法(丑陋):

var modal_func_to_run;  
$("#my-modal").on('hidden', function(){
    if ( modal_func_to_run == 'first' )
        alert("This will fire in IE");
    else if ( modal_func_to_run == 'second' )
        alert("The second button was clicked!");
});
// ....
$('#my-btn').on('click', function() {
    modal_func_to_run = 'first';
    $('#my-modal').hide();
});

有没有人有更好的方法来解决 Internet Explorer 中的问题?

我运行 Bootstrap 2.3.2 和 jQuery 1.10.1。

4

1 回答 1

1

尝试

$('#my-btn').on('click', function() {
    $("#my-modal").on('hidden', function(){
        alert("This wont fire in IE first time around");
    }).modal('hide');
});

只需更改绑定顺序,以便事件处理程序在隐藏调用之前绑定到模式

于 2013-09-10T13:50:42.330 回答