javascript - 使用 jquery 仅删除一个事件处理程序 ".off"

标签 javascript jquery twitter-bootstrap

我从某处借用了这段代码,以从一种 Bootstrap 模式切换到另一种模式。切换后,我想关闭处理程序,这样每次我只需关闭第一个模态时它就不会切换。我的问题是,一旦使用模态切换功能,我不知道如何关闭特定事件处理程序,而不关闭在某个模态关闭时触发的其他事件(在其他地方完成) )。有什么建议吗?

//switch modals
function switchModals(fromModal, toModal) {
    $(fromModal).on('hidden.bs.modal', function (e) {
        $(toModal).modal('show');
        //clear this function so it doesn't show up if they exit the window again
        $(fromModal).off('hidden.bs.modal');
    });
    $(fromModal).modal('hide');
}

最佳答案

您需要将此行放在 switchModals 之外

$(<FromModalId>).modal('hide');

关于javascript - 使用 jquery 仅删除一个事件处理程序 ".off",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38176845/

相关文章:

javascript - 从 PagedListPager 调用 JavaScript 函数

twitter-bootstrap - 使用 bootstrap 4 是否安全,因为它是 alpha 版本?

javascript - 如何使用带有 Angular js 和 Bootstrap 的 "Cancel"按钮关闭模态

javascript - Mottie jQuery Tablesorter 过滤器未在页面上加载

javascript - Bootstrap star-rating inside popover CSS 问题

javascript - 从网络浏览器打开/关闭移动手电筒

jquery - 在jquery中组合多个函数

javascript - 同步跨域 javascript 调用,等待响应 - 这可能吗?

javascript - 在 jquery 函数中插入 html 代码

jquery - 无论排序如何,如何获取最后一个表行?