我有一个bootstrap弹出窗口,它在输入的focus上激活。弹出框中包含一个按钮,用于执行ajax请求。
我有一个blur函数,它可以在用户离开输入时关闭弹出窗口:
$(document).on('blur','.open-popover',function(){
$(".popover").attr("style","");
//and do other things too
});我正在尝试阻止上面的blur函数在用户按下弹出窗口中的按钮时运行:
$(document).on('click','button',function(){
//prevent the blur actions and
//do ajax stuff
});发布于 2015-06-26 06:04:39
你看过stopImmediatePropagation吗?如果使用jQuery,则按绑定的顺序触发事件处理程序。只需在模糊之前绑定单击,并在单击事件中运行stopImmediatePropagation。
// 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
});https://stackoverflow.com/questions/31061523
复制相似问题