首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >阻止blur()运行

阻止blur()运行
EN

Stack Overflow用户
提问于 2015-06-26 05:59:11
回答 1查看 3.2K关注 0票数 2

我有一个bootstrap弹出窗口,它在输入的focus上激活。弹出框中包含一个按钮,用于执行ajax请求。

我有一个blur函数,它可以在用户离开输入时关闭弹出窗口:

代码语言:javascript
复制
$(document).on('blur','.open-popover',function(){        
    $(".popover").attr("style","");
    //and do other things too  
});

我正在尝试阻止上面的blur函数在用户按下弹出窗口中的按钮时运行:

代码语言:javascript
复制
$(document).on('click','button',function(){
    //prevent the blur actions and 
    //do ajax stuff                                   
});
EN

回答 1

Stack Overflow用户

发布于 2015-06-26 06:04:39

你看过stopImmediatePropagation吗?如果使用jQuery,则按绑定的顺序触发事件处理程序。只需在模糊之前绑定单击,并在单击事件中运行stopImmediatePropagation。

代码语言:javascript
复制
// bind click event first
$(document).on('click','button',function(event){
    // keeps the rest of the handlers from being executed and prevents the event from bubbling up the DOM tree.
    event.stopImmediatePropagation();                            
});

// then attach blur
$(document).on('blur','.open-popover',function(){        
    $(".popover").attr("style","");
    //and do other things too  
});
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31061523

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档