Jquery ui 单击后输入有焦点时,不要关闭工具提示
如果输入具有焦点,如何使工具提示不关闭?当它通过tab获得焦点时,它会工作,但如果我使用鼠标聚焦输入,即使输入具有焦点,工具提示也会在Jquery ui 单击后输入有焦点时,不要关闭工具提示,jquery-ui,tooltip,Jquery Ui,Tooltip,如果输入具有焦点,如何使工具提示不关闭?当它通过tab获得焦点时,它会工作,但如果我使用鼠标聚焦输入,即使输入具有焦点,工具提示也会在mouseout上关闭 我能行 $('input').tooltip().off("mouseover mouseout"); 但这将在悬停时禁用工具提示,我只需要在input有焦点时禁用mouseout 试试这个: 新的改进方法: $("input").tooltip({ hide: { effect: 'explode'// a
mouseout
上关闭
我能行
$('input').tooltip().off("mouseover mouseout");
但这将在悬停时禁用工具提示,我只需要在input
有焦点时禁用mouseout
试试这个: 新的改进方法:
$("input").tooltip({
hide: {
effect: 'explode'// added for visibility
}
}).mouseleave(function () { // on mouse leave
if ($('input').is(':focus')) { // if input is focused
ui.tooltip.preventDefault(); //prevent the tooltip's default behavior
$('input').tooltip('open'); // leave the tooltip open
}
}).focusout(function () { // on focus out
$('input').tooltip('close'); // close the tooltip
});
API文档:我没有添加所有其他侦听器,而是研究了实际情况,决定最有效的方法是继承小部件并添加一个额外的标志 这里有一个演示
与其他解决方案相比,这不需要我们对额外的open调用做更多的工作(它实际上在其中执行其他几个调用)。我们只是按照原始帖子的要求,在关注元素时阻止工具提示关闭。修复ui错误所需做的唯一一件事就是将其作为每个文档的参数传递进来
那么,您希望在输入具有焦点时显示(并保持显示)工具提示吗?当您将鼠标悬停在输入上而它没有焦点时,情况会怎样?您想要标准的工具提示吗?或者您希望工具提示仅在元素具有焦点时显示?悬停应该可以工作,但如果元素具有焦点,则不应关闭工具提示。
hoverout
可以工作,但鼠标悬停时工具提示会闪烁(快速关闭和打开)。如果没有其他方法,我将使用它“代码>行”似乎只起作用,因为它会导致错误,从而阻止工具提示关闭——显然这可能是不可取的。我发现完成同样事情的唯一简单方法是e.stopImmediatePropagation()代码>在它的位置。
$("input").tooltip({
hide: {
effect: 'explode'// added for visibility
}
}).mouseleave(function () { // on mouse leave
if ($('input').is(':focus')) { // if input is focused
ui.tooltip.preventDefault(); //prevent the tooltip's default behavior
$('input').tooltip('open'); // leave the tooltip open
}
}).focusout(function () { // on focus out
$('input').tooltip('close'); // close the tooltip
});
(function ($) {
$.widget("custom.tooltipX", $.ui.tooltip, {
options: {
focusPreventClose: false
},
close: function (event, target, content) {
if (this.options.focusPreventClose && $(this.element).is(":focus")) {
// Don't call the parent's close() call but therefore have to add event on focus out
this._on({ focusout:this.close });
} else {
this._superApply(arguments);
}
}
});
}(jQuery));
$('input').tooltipX({
focusPreventClose: true
});
$(document).tooltip({ selector: "[title]" }).mouseleave(function(event, ui) {
if ($('input').is(':focus')) {
ui.tooltip.preventDefault();
$('input').tooltip('open');
}
});