gpt4 book ai didi

jquery - Internet Explorer 中 Bootstrap 模式事件的问题

转载 作者:行者123 更新时间:2023-12-01 04:52:00 25 4
gpt4 key购买 nike

我在 Internet Explorer 中遇到 Bootstrap Modal 事件问题。

我正在构建的网站中有多个模式,每个模式都有许多链接,一旦模式被隐藏,单击这些链接就会执行不同的操作。问题是,除非模式已在 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。

最佳答案

尝试

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

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

关于jquery - Internet Explorer 中 Bootstrap 模式事件的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18720524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com